-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: TokenProvider 에서 각 토큰에 대한 로직을 캡슐화 #183
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
Conversation
| 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); |
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.
기존에는 '액세스 토큰은 생성', '리프레시 토큰은 생성과 저장'을 하도록 코드로 작성했어야 했었습니다.
이 과정을 함수로 캡슐화하여 실수를 방지했습니다!
| public String saveToken(String token, TokenType tokenType) { | ||
| String subject = parseSubject(token, jwtProperties.secret()); | ||
| redisTemplate.opsForValue().set( |
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.
예를 들어 기존에는 TokenType을 넘겨주어 토큰을 저장하게 했었습니다.
그런데 사실 엑세스 토큰은 별도로 저장할 필요가 없음에도, 그 가능성을 열어두었었습니다.
이 리팩터링에서는 로직을 함수 이름으로 특정하여 제약을 걸어주었습니다.
| // 액세스 토큰 재발급 | ||
| String newAccessToken = tokenProvider.generateToken(subject, ACCESS); | ||
| tokenProvider.saveToken(newAccessToken, ACCESS); | ||
| String newAccessToken = tokenProvider.generateAccessToken(subject); | ||
| return new ReissueResponse(newAccessToken); |
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.
이렇게 엑세스 토큰을 저장하는 실수가 가능했습니다....😅
지금은 엑세스 토큰을 저장할 수 없어졌씁니다~
wibaek
left a comment
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.
lgtm
작업 내용
#171 (comment) 이 코멘트의 내용을 적용했습니다.
처음에는 리팩터링 우선순위가 높지 않다고 생각했었는데,.
애플 로그인을 구현하며 SignUpToken 생성, 저장 로직을 구현하다보니 기존 함수들을 어떻게 사용해야할지 헷갈리더라고요😵💫
왜냐하면 기존에는 TokenProvider 에서 TokenType 을 인자로 받게하고,
개발자가 이들을 함수를 조합해서 사용하게 했기 때문입니다.
그래서 확장성은 고려되었지만, 각각의 타입에 맞는 제약은 개발자 개인에게 달려있었어요.
게다가 위백님이 짚어주신 것처럼, '왜 여기에서는 오버로딩을 했지?'하는 의문도 들게 하고요.
그래서 TokenProvider 에서 각 토큰에 대한 로직을 캡슐화하도록 코드를 변경했습니다.
특이 사항
다른 특이사항은 코멘트로 남길게요!