From c5a18f0d143db04b40d9c172e6b3ad966c23fa3c Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Thu, 19 Oct 2023 20:59:30 +0900 Subject: [PATCH] =?UTF-8?q?Fix(#35):=20=ED=86=A0=ED=81=B0=20=EA=B0=B1?= =?UTF-8?q?=EC=8B=A0=EC=8B=9C=20refresh=20token=EB=8F=84=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20=EA=B0=B1=EC=8B=A0=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/token/dto/response/RefreshTokenResponse.java | 7 +++++-- .../com/numberone/backend/domain/token/entity/Token.java | 5 +++-- .../backend/domain/token/service/TokenService.java | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/numberone/backend/domain/token/dto/response/RefreshTokenResponse.java b/src/main/java/com/numberone/backend/domain/token/dto/response/RefreshTokenResponse.java index fc3b7d09..1423570d 100644 --- a/src/main/java/com/numberone/backend/domain/token/dto/response/RefreshTokenResponse.java +++ b/src/main/java/com/numberone/backend/domain/token/dto/response/RefreshTokenResponse.java @@ -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(); } } diff --git a/src/main/java/com/numberone/backend/domain/token/entity/Token.java b/src/main/java/com/numberone/backend/domain/token/entity/Token.java index 7baa053b..0778a852 100644 --- a/src/main/java/com/numberone/backend/domain/token/entity/Token.java +++ b/src/main/java/com/numberone/backend/domain/token/entity/Token.java @@ -28,7 +28,7 @@ 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) @@ -36,7 +36,8 @@ public static Token of(String email, String accessToken, String refreshToken){ .build(); } - public void updateAccessToken(String accessToken) { + public void update(String accessToken, String refreshToken) { this.accessToken = accessToken; + this.refreshToken = refreshToken; } } diff --git a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java index f80e2ed8..64400c98 100644 --- a/src/main/java/com/numberone/backend/domain/token/service/TokenService.java +++ b/src/main/java/com/numberone/backend/domain/token/service/TokenService.java @@ -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