Skip to content
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

Fix(#35): 토큰 갱신시 refresh token도 함께 갱신되도록 수정 #36

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
@Getter
public class RefreshTokenResponse {
private String accessToken;
private String refreshToken;

@Builder
public RefreshTokenResponse(String accessToken) {
public RefreshTokenResponse(String accessToken,String refreshToken) {
this.accessToken = accessToken;
this.refreshToken= refreshToken;
}

public static RefreshTokenResponse of(String accessToken) {
public static RefreshTokenResponse of(String accessToken, String refreshToken) {
return RefreshTokenResponse.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public Token(String email, String accessToken, String refreshToken) {
this.refreshToken = refreshToken;
}

public static Token of(String email, String accessToken, String refreshToken){
public static Token of(String email, String accessToken, String refreshToken) {
return Token.builder()
.email(email)
.accessToken(accessToken)
.refreshToken(refreshToken)
.build();
}

public void updateAccessToken(String accessToken) {
public void update(String accessToken, String refreshToken) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public RefreshTokenResponse refresh(RefreshTokenRequest tokenRequest) {
Token token = tokenRepository.findByRefreshToken(tokenRequest.getToken())
.orElseThrow(NotFoundRefreshTokenException::new);
String email = jwtUtil.getEmail(tokenRequest.getToken());
String newToken = jwtUtil.createToken(email, accessPeroid);
token.updateAccessToken(newToken);
String newAccessToken = jwtUtil.createToken(email, accessPeroid);
String newRefreshToken = jwtUtil.createToken(email, refreshPeroid);
token.update(newAccessToken,newRefreshToken);
tokenRepository.save(token);//redis의 경우 jpa와 달리 transactional을 이용해도 데이터 수정시에 명시적으로 save를 해줘야 함
Copy link
Member

Choose a reason for hiding this comment

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

👍

return RefreshTokenResponse.of(newToken);
return RefreshTokenResponse.of(newAccessToken,newRefreshToken);
}

@Transactional
Expand Down
Loading