-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#61] refreshToken 보내면 새로운 token 들 반환 #62
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a05bf42
Feat : apple 로그인 과정에서 token expire 에러 처리
namewhat99 66bac6f
Feat : refreshToken 발급 로직 작성
namewhat99 90f6545
Feat : controller 작성
namewhat99 c07bc49
Feat : module 작성
namewhat99 fd26565
Feat : 중복 제거
namewhat99 7292a0c
Fix: 분기문 삭제
namewhat99 aaf80b0
Fix: url 매칭 설정
namewhat99 7b50b55
Fix: 폴더 구조 변경
namewhat99 1bab13c
Fix: app 모듈 변경
namewhat99 2b7938e
Fix: accessToken expiresIn 추가
namewhat99 d69e9fb
Fix: accessToken option 삭제
namewhat99 45a4059
Merge branch 'develop' into feature/jwtRefresh-#61
koomin1227 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
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 |
---|---|---|
|
@@ -27,8 +27,8 @@ export class AuthService { | |
user = await this.userService.createUser(providerId); | ||
await this.totalService.createTotalPoint(user.userId); | ||
} | ||
const accessToken = this.generateAccessToken(user); | ||
const refreshToken = this.generateRefreshToken(user); | ||
const accessToken = this.generateAccessToken(user.userId); | ||
const refreshToken = this.generateRefreshToken(user.userId); | ||
return { accessToken, refreshToken, isMember }; | ||
} | ||
|
||
|
@@ -42,16 +42,16 @@ export class AuthService { | |
); | ||
} | ||
|
||
generateAccessToken(user: User): string { | ||
generateAccessToken(userId: string): string { | ||
return this.jwtService.sign({ | ||
userId: user.userId, | ||
userId: userId, | ||
}); | ||
} | ||
|
||
generateRefreshToken(user: User): string { | ||
generateRefreshToken(userId: string): string { | ||
return this.jwtService.sign( | ||
{ | ||
userId: user.userId, | ||
userId: userId, | ||
}, | ||
{ | ||
secret: this.configService.get('JWT_REFRESH_SECRET'), | ||
|
@@ -143,4 +143,25 @@ export class AuthService { | |
return { isAuthorized: isSejongJson.result.is_auth }; | ||
} | ||
} | ||
|
||
public sendTokens(refreshToken: string) { | ||
const payload = this.validateRefreshToken(refreshToken); | ||
|
||
return { | ||
accessToken: this.generateAccessToken(payload.userId), | ||
refreshToken: this.generateRefreshToken(payload.userId), | ||
}; | ||
} | ||
|
||
public validateRefreshToken(refreshToken: string) { | ||
try { | ||
return this.jwtService.verify(refreshToken, { | ||
secret: this.configService.get('JWT_REFRESH_SECRET'), | ||
}); | ||
} catch (e) { | ||
if (e instanceof TokenExpiredError) { | ||
throw new UnauthorizedException(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러 핸들링이 잘 되어네요! |
||
} | ||
} | ||
} | ||
} |
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.
이렇게 하면 refresh token으로 숫자가 오면 어떻게 되나요? 400이 나오나요 500이 나오나요?