Skip to content

Commit

Permalink
Fix(#35): 토큰 갱신시 refresh token도 함께 갱신되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
nohy6630 committed Oct 19, 2023
1 parent 990ec30 commit c5a18f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
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를 해줘야 함
return RefreshTokenResponse.of(newToken);
return RefreshTokenResponse.of(newAccessToken,newRefreshToken);
}

@Transactional
Expand Down

0 comments on commit c5a18f0

Please sign in to comment.