refactor: TokenProvider 에서 각 토큰에 대한 로직을 캡슐화#183
Merged
Conversation
nayonsoso
commented
Feb 5, 2025
Comment on lines
+63
to
+64
| String accessToken = tokenProvider.generateToken(siteUser, TokenType.ACCESS); | ||
| String refreshToken = tokenProvider.generateToken(siteUser, TokenType.REFRESH); | ||
| tokenProvider.saveToken(refreshToken, TokenType.REFRESH); | ||
| String accessToken = tokenProvider.generateAccessToken(siteUser); | ||
| String refreshToken = tokenProvider.generateAndSaveRefreshToken(siteUser); |
Collaborator
Author
There was a problem hiding this comment.
기존에는 '액세스 토큰은 생성', '리프레시 토큰은 생성과 저장'을 하도록 코드로 작성했어야 했었습니다.
이 과정을 함수로 캡슐화하여 실수를 방지했습니다!
Comment on lines
71
to
73
| public String saveToken(String token, TokenType tokenType) { | ||
| String subject = parseSubject(token, jwtProperties.secret()); | ||
| redisTemplate.opsForValue().set( |
Collaborator
Author
There was a problem hiding this comment.
예를 들어 기존에는 TokenType을 넘겨주어 토큰을 저장하게 했었습니다.
그런데 사실 엑세스 토큰은 별도로 저장할 필요가 없음에도, 그 가능성을 열어두었었습니다.
이 리팩터링에서는 로직을 함수 이름으로 특정하여 제약을 걸어주었습니다.
Comment on lines
65
to
54
| // 액세스 토큰 재발급 | ||
| String newAccessToken = tokenProvider.generateToken(subject, ACCESS); | ||
| tokenProvider.saveToken(newAccessToken, ACCESS); | ||
| String newAccessToken = tokenProvider.generateAccessToken(subject); | ||
| return new ReissueResponse(newAccessToken); |
Collaborator
Author
There was a problem hiding this comment.
이렇게 엑세스 토큰을 저장하는 실수가 가능했습니다....😅
지금은 엑세스 토큰을 저장할 수 없어졌씁니다~
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
작업 내용
#171 (comment) 이 코멘트의 내용을 적용했습니다.
처음에는 리팩터링 우선순위가 높지 않다고 생각했었는데,.
애플 로그인을 구현하며 SignUpToken 생성, 저장 로직을 구현하다보니 기존 함수들을 어떻게 사용해야할지 헷갈리더라고요😵💫
왜냐하면 기존에는 TokenProvider 에서 TokenType 을 인자로 받게하고,
개발자가 이들을 함수를 조합해서 사용하게 했기 때문입니다.
그래서 확장성은 고려되었지만, 각각의 타입에 맞는 제약은 개발자 개인에게 달려있었어요.
게다가 위백님이 짚어주신 것처럼, '왜 여기에서는 오버로딩을 했지?'하는 의문도 들게 하고요.
그래서 TokenProvider 에서 각 토큰에 대한 로직을 캡슐화하도록 코드를 변경했습니다.
특이 사항
다른 특이사항은 코멘트로 남길게요!