Skip to content

Conversation

@nayonsoso
Copy link
Collaborator

작업 내용

image

#171 (comment) 이 코멘트의 내용을 적용했습니다.
처음에는 리팩터링 우선순위가 높지 않다고 생각했었는데,.
애플 로그인을 구현하며 SignUpToken 생성, 저장 로직을 구현하다보니 기존 함수들을 어떻게 사용해야할지 헷갈리더라고요😵‍💫
왜냐하면 기존에는 TokenProvider 에서 TokenType 을 인자로 받게하고,
개발자가 이들을 함수를 조합해서 사용하게 했기 때문입니다.
그래서 확장성은 고려되었지만, 각각의 타입에 맞는 제약은 개발자 개인에게 달려있었어요.
게다가 위백님이 짚어주신 것처럼, '왜 여기에서는 오버로딩을 했지?'하는 의문도 들게 하고요.
그래서 TokenProvider 에서 각 토큰에 대한 로직을 캡슐화하도록 코드를 변경했습니다.

특이 사항

다른 특이사항은 코멘트로 남길게요!

@nayonsoso nayonsoso self-assigned this 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);
Copy link
Collaborator Author

@nayonsoso nayonsoso Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에는 '액세스 토큰은 생성', '리프레시 토큰은 생성과 저장'을 하도록 코드로 작성했어야 했었습니다.
이 과정을 함수로 캡슐화하여 실수를 방지했습니다!

Comment on lines 71 to 73
public String saveToken(String token, TokenType tokenType) {
String subject = parseSubject(token, jwtProperties.secret());
redisTemplate.opsForValue().set(
Copy link
Collaborator Author

@nayonsoso nayonsoso Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예를 들어 기존에는 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);
Copy link
Collaborator Author

@nayonsoso nayonsoso Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 엑세스 토큰을 저장하는 실수가 가능했습니다....😅
지금은 엑세스 토큰을 저장할 수 없어졌씁니다~

Copy link
Member

@wibaek wibaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nayonsoso nayonsoso merged commit ecc186a into main Feb 6, 2025
@nayonsoso nayonsoso deleted the refactor/token-provider-encapsulation branch February 15, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants