-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature 2fa #213
Merged
Merged
Feature 2fa #213
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
53f8119
Create migration
PhamAnhHoang 886eccb
Backend api for 2FA feature
PhamAnhHoang ee468b8
Recovery 2fa feature
PhamAnhHoang 22309b6
Update yarn lock
PhamAnhHoang 8efb0ca
Fix email template
PhamAnhHoang b881010
Add 2fa to front end
PhamAnhHoang 4a219fd
Implement recovery process, fix bugs
PhamAnhHoang ecde1cf
Update disable 2fa email and flow
PhamAnhHoang 9cf46d9
added default value for jwt expirity
vygandas 101bd73
Fix comment
PhamAnhHoang 6d6474d
Fix test
PhamAnhHoang 22a8725
Fix recovery codes display error and double toast message
PhamAnhHoang e63dbbe
Turn off 2fa
PhamAnhHoang 0585541
Turn of 2fa platform
PhamAnhHoang ba4b89f
Fix lint
PhamAnhHoang 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 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 @@ | ||
nodeLinker: node-modules |
This file contains 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 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 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 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,5 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { AuthGuard } from '@nestjs/passport' | ||
|
||
@Injectable() | ||
export class Jwt2faAuthGuard extends AuthGuard('jwt-2fa') {} |
This file contains 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,32 @@ | ||
import { ExtractJwt, Strategy } from 'passport-jwt' | ||
import { PassportStrategy } from '@nestjs/passport' | ||
import { Injectable } from '@nestjs/common' | ||
import { UserService } from '../../user/user.service' | ||
import { LoginWith2FAPayload } from '@isomera/interfaces' | ||
|
||
@Injectable() | ||
export class Jwt2faStrategy extends PassportStrategy(Strategy, 'jwt-2fa') { | ||
constructor(private readonly userService: UserService) { | ||
super({ | ||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), | ||
secretOrKey: process.env.APP_SECRET | ||
}) | ||
} | ||
|
||
async validate(payload: LoginWith2FAPayload) { | ||
const user = await this.userService.findOne({ | ||
where: { email: payload.email } | ||
}) | ||
|
||
if (!user.isTwoFAEnabled) { | ||
return user | ||
} | ||
|
||
if (payload.isTwoFactorAuthenticated) { | ||
return { | ||
...user, | ||
isTwoFactorAuthenticated: payload.isTwoFactorAuthenticated | ||
} | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this prop already be in UserEntity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field doesn't exist in the entity because it's not being stored in the db