Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
9be7c7bf
Commit
9be7c7bf
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Session => Add session refresh
parent
937a4611
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExpressAPI/src/controllers/Session.ts
+6
-2
6 additions, 2 deletions
ExpressAPI/src/controllers/Session.ts
ExpressAPI/src/middlewares/SessionMiddleware.ts
+2
-1
2 additions, 1 deletion
ExpressAPI/src/middlewares/SessionMiddleware.ts
with
8 additions
and
3 deletions
ExpressAPI/src/controllers/Session.ts
+
6
−
2
View file @
9be7c7bf
...
@@ -5,6 +5,7 @@ import Config from '../config/Config';
...
@@ -5,6 +5,7 @@ import Config from '../config/Config';
import
express
from
'
express
'
;
import
express
from
'
express
'
;
import
ApiRequest
from
'
../models/ApiRequest
'
;
import
ApiRequest
from
'
../models/ApiRequest
'
;
import
User
from
'
../models/User
'
;
import
User
from
'
../models/User
'
;
import
UserManager
from
'
../managers/UserManager
'
;
class
Session
{
class
Session
{
...
@@ -19,16 +20,19 @@ class Session {
...
@@ -19,16 +20,19 @@ class Session {
this
.
_profile
=
newProfile
;
this
.
_profile
=
newProfile
;
}
}
constructor
(
req
:
ApiRequest
)
{
constructor
()
{
}
async
initSession
(
req
:
ApiRequest
)
{
const
authorization
=
req
.
headers
.
authorization
;
const
authorization
=
req
.
headers
.
authorization
;
if
(
authorization
)
{
if
(
authorization
)
{
const
jwtToken
=
authorization
.
replace
(
'
Bearer
'
,
''
);
const
jwtToken
=
authorization
.
replace
(
'
Bearer
'
,
''
);
try
{
try
{
const
jwtData
=
jwt
.
verify
(
jwtToken
,
Config
.
jwt
S
ecret
Key
)
as
JwtPayload
;
const
jwtData
=
jwt
.
verify
(
jwtToken
,
Config
.
jwt
Config
.
s
ecret
)
as
JwtPayload
;
if
(
jwtData
.
profile
)
{
if
(
jwtData
.
profile
)
{
this
.
profile
.
importFromJsonObject
(
jwtData
.
profile
);
this
.
profile
.
importFromJsonObject
(
jwtData
.
profile
);
this
.
profile
=
await
UserManager
.
getById
(
this
.
profile
.
userID
);
this
.
profile
.
currentSession
=
this
;
this
.
profile
.
currentSession
=
this
;
}
}
}
catch
(
err
)
{
}
}
catch
(
err
)
{
}
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/middlewares/SessionMiddleware.ts
+
2
−
1
View file @
9be7c7bf
...
@@ -18,7 +18,8 @@ class SessionMiddleware {
...
@@ -18,7 +18,8 @@ class SessionMiddleware {
register
():
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
void
{
register
():
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
void
{
return
async
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
return
async
(
req
:
ApiRequest
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
req
.
session
=
new
Session
(
req
);
req
.
session
=
new
Session
();
await
req
.
session
.
initSession
(
req
);
return
next
();
return
next
();
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment