-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/login formular #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 27 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
d1018ab
composant login, composant logo et page login faites(mobile)
sadjoaldi 87d41d0
page login, signup, forgotten password done
sadjoaldi 9d5224c
bug build
sadjoaldi 4282fa1
bug build
sadjoaldi 97024fe
bug build
sadjoaldi 26faf67
merge develop
sadjoaldi 9151867
pull develop
sadjoaldi ba2db5d
ajustement style
sadjoaldi 92a6377
register&login back ok, login front ok
sadjoaldi a5c3381
renommage de fichiers, register et login ok front et back
sadjoaldi 940e59d
cheik error
sadjoaldi 14b1fcb
cheik error
sadjoaldi 626410c
cheik error
sadjoaldi ffb02e8
correction
sadjoaldi c30c060
register, login, logout good
sadjoaldi 8d9f34e
register, login, logout ok
sadjoaldi b1ae9eb
Merge branch 'develop' into feature/login-formular
sadjoaldi dada3ee
register,login, logout
sadjoaldi fe40730
register,login, logout
sadjoaldi d19dfe1
corrections
sadjoaldi 07d13d2
regis, log, cook
sadjoaldi c68a1c0
pull
sadjoaldi 143c9e8
Merge branch 'develop' into feature/login-formular
sadjoaldi 7b4c593
pull
sadjoaldi 0251665
pull
sadjoaldi bb00354
pull
sadjoaldi 2a47c44
corrections
sadjoaldi 8561465
correct
sadjoaldi c2bcfdd
Delete .vscode/settings.json
TeddyAgt f0d6d56
recup user
sadjoaldi 99e8a66
correction pr
sadjoaldi ff834c6
correction pr
sadjoaldi 3498528
Delete .vscode/settings.json
TeddyAgt a7fa47a
correction authentification
sadjoaldi 1966e25
correction
sadjoaldi 0e6997d
correction authmiddl
sadjoaldi e2079ea
rename newAccessToken à accessToken ligne 55 et 66 de authmiddleware
sadjoaldi 04d5919
creation fichier cookie-router, ajout dans authrouter, ajout de type …
sadjoaldi f3b8a0b
vscode settings
sadjoaldi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TeddyAgt marked this conversation as resolved.
Show resolved
Hide resolved
sadjoaldi marked this conversation as resolved.
Show resolved
Hide resolved
TeddyAgt marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"Devdb.colorTheme": "dark" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { NextFunction, Request, Response } from 'express'; | ||
|
||
export default function loginGuards( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) { | ||
if (req.isAuthenticated === true) { | ||
next(); | ||
return; | ||
} | ||
|
||
res.json({ | ||
ok: false, | ||
}); | ||
return; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import type { NextFunction, Request, Response } from 'express'; | ||
import * as jose from 'jose'; | ||
|
||
import { env } from '@app/shared'; | ||
|
||
const FRONTEND_HOST = process.env.FRONTEND_HOST ?? ''; | ||
|
||
env(); | ||
|
||
const ACCESS_TOKEN_SECRET = process.env.ACCESS_TOKEN_SECRET; | ||
const accessTokenSecret = new TextEncoder().encode(ACCESS_TOKEN_SECRET); | ||
|
||
const REFRESH_TOKEN_SECRET = process.env.REFRESH_TOKEN_SECRET; | ||
const refreshTokenSecret = new TextEncoder().encode(REFRESH_TOKEN_SECRET); | ||
|
||
export default async function loginMiddleware( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) { | ||
// Check if the request has a signed cookie named accessToken | ||
const accessToken = req.signedCookies.accessToken; | ||
|
||
if (accessToken === undefined) { | ||
console.error('accessToken is missing in signed cookies'); | ||
res.status(401).json({ ok: false, message: 'accessToken is missing' }); | ||
return; | ||
} | ||
|
||
try { | ||
// Verify the access token and extract the payload | ||
const { payload } = await jose.jwtVerify<{ userId: number }>( | ||
accessToken, | ||
accessTokenSecret, | ||
{ | ||
audience: FRONTEND_HOST, | ||
issuer: FRONTEND_HOST, | ||
}, | ||
); | ||
|
||
// If the access token is valid: | ||
|
||
req.isAuthenticated = true; | ||
req.userId = payload.userId; | ||
} catch (aterror) { | ||
console.error(aterror); | ||
sadjoaldi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// If the access token is invalid, we check if the refresh token is present | ||
const refreshToken = req.signedCookies.refreshToken; | ||
|
||
try { | ||
const { payload } = await jose.jwtVerify<{ userId: number }>( | ||
refreshToken, | ||
refreshTokenSecret, | ||
{ | ||
audience: FRONTEND_HOST, | ||
issuer: FRONTEND_HOST, | ||
}, | ||
); | ||
|
||
// If the refresh token is valid, we create a new access token and set it in the cookie | ||
|
||
const newAccessToken = await new jose.SignJWT({ | ||
sub: payload.sub, | ||
userId: payload.userId, | ||
}) | ||
.setProtectedHeader({ alg: 'HS256' }) | ||
.setIssuedAt() | ||
.setIssuer(FRONTEND_HOST) | ||
.setAudience(FRONTEND_HOST) | ||
.setExpirationTime('60s') | ||
.sign(accessTokenSecret); | ||
|
||
res.cookie('newAccessToken', newAccessToken, { | ||
httpOnly: true, | ||
signed: true, | ||
// secure: true, | ||
// sameSite: 'strict', | ||
}); | ||
|
||
req.isAuthenticated = true; | ||
req.userId = payload.userId; | ||
} catch (rterror) { | ||
console.error('Refresh token is invalid', rterror); | ||
sadjoaldi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// If the refresh token is invalid, | ||
req.isAuthenticated = false; | ||
return; | ||
sadjoaldi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
next(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.