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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
690cfff7
Commit
690cfff7
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Session => Add response if the token read fail
parent
2f5fb61a
Branches
Branches containing commit
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
+12
-10
12 additions, 10 deletions
ExpressAPI/src/controllers/Session.ts
ExpressAPI/src/middlewares/SessionMiddleware.ts
+1
-1
1 addition, 1 deletion
ExpressAPI/src/middlewares/SessionMiddleware.ts
with
13 additions
and
11 deletions
ExpressAPI/src/controllers/Session.ts
+
12
−
10
View file @
690cfff7
import
{
getReasonPhrase
}
from
'
http-status-codes
'
;
import
{
getReasonPhrase
,
StatusCodes
}
from
'
http-status-codes
'
;
import
*
as
jwt
from
'
jsonwebtoken
'
;
import
*
as
jwt
from
'
jsonwebtoken
'
;
import
{
JwtPayload
}
from
'
jsonwebtoken
'
;
import
{
JwtPayload
}
from
'
jsonwebtoken
'
;
import
Config
from
'
../config/Config
'
;
import
Config
from
'
../config/Config
'
;
...
@@ -22,7 +22,7 @@ class Session {
...
@@ -22,7 +22,7 @@ class Session {
constructor
()
{
}
constructor
()
{
}
async
initSession
(
req
:
express
.
Request
)
{
async
initSession
(
req
:
express
.
Request
,
res
:
express
.
Response
)
{
const
authorization
=
req
.
headers
.
authorization
;
const
authorization
=
req
.
headers
.
authorization
;
if
(
authorization
)
{
if
(
authorization
)
{
if
(
authorization
.
startsWith
(
'
Bearer
'
)
)
{
if
(
authorization
.
startsWith
(
'
Bearer
'
)
)
{
...
@@ -35,7 +35,9 @@ class Session {
...
@@ -35,7 +35,9 @@ class Session {
this
.
profile
=
jwtData
.
profile
;
this
.
profile
=
jwtData
.
profile
;
this
.
profile
=
await
UserManager
.
getById
(
this
.
profile
.
id
!
)
??
this
.
profile
;
this
.
profile
=
await
UserManager
.
getById
(
this
.
profile
.
id
!
)
??
this
.
profile
;
}
}
}
catch
(
err
)
{
}
}
catch
(
err
)
{
res
.
sendStatus
(
StatusCodes
.
UNAUTHORIZED
).
end
();
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/middlewares/SessionMiddleware.ts
+
1
−
1
View file @
690cfff7
...
@@ -6,7 +6,7 @@ class SessionMiddleware {
...
@@ -6,7 +6,7 @@ class SessionMiddleware {
register
():
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
void
{
register
():
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
void
{
return
async
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
return
async
(
req
:
express
.
Request
,
res
:
express
.
Response
,
next
:
express
.
NextFunction
)
=>
{
req
.
session
=
new
Session
();
req
.
session
=
new
Session
();
await
req
.
session
.
initSession
(
req
);
await
req
.
session
.
initSession
(
req
,
res
);
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