From 8806e9fc4ec655fc22437c76cd9afaf31897bcf0 Mon Sep 17 00:00:00 2001 From: ckkim817 Date: Mon, 3 Jun 2024 03:10:40 +0900 Subject: [PATCH] =?UTF-8?q?Refresh=20Token=20=EB=A7=8C=EB=A3=8C=20?= =?UTF-8?q?=EC=8B=9C=20ErrorMessage=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/redis/service/TokenService.java | 12 ++---------- .../sopt/springPractice/common/dto/ErrorMessage.java | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/auth/redis/service/TokenService.java b/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/auth/redis/service/TokenService.java index eb739ee..fe3f5e5 100644 --- a/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/auth/redis/service/TokenService.java +++ b/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/auth/redis/service/TokenService.java @@ -6,7 +6,6 @@ import org.sopt.springPractice.auth.redis.service.dto.AccessTokenDTO; import org.sopt.springPractice.common.dto.ErrorMessage; import org.sopt.springPractice.common.jwt.JwtTokenProvider; -import org.sopt.springPractice.common.jwt.JwtValidationType; import org.sopt.springPractice.exception.UnauthorizedException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,17 +20,10 @@ public class TokenService { @Transactional public AccessTokenDTO reissueAccessToken(Long userId) { Token token = redisTokenRepository.findById(userId).orElseThrow( - () -> new UnauthorizedException(ErrorMessage.REFRESH_TOKEN_NOT_FOUND) + () -> new UnauthorizedException(ErrorMessage.MEMBER_NOT_FOUND) ); - JwtValidationType validationType = jwtTokenProvider.validateToken(token.getRefreshToken()); - - if (validationType == JwtValidationType.EXPIRED_JWT_TOKEN) { - throw new UnauthorizedException(ErrorMessage.JWT_UNAUTHORIZED_EXCEPTION); - } else if (validationType != JwtValidationType.VALID_JWT) { - throw new UnauthorizedException(ErrorMessage.JWT_UNAUTHORIZED_EXCEPTION); - } - + jwtTokenProvider.validateToken(token.getRefreshToken()); String newAccessToken = jwtTokenProvider.newAccessToken(token.getRefreshToken()); return AccessTokenDTO.of(newAccessToken); diff --git a/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/common/dto/ErrorMessage.java b/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/common/dto/ErrorMessage.java index 032447c..a3989ec 100644 --- a/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/common/dto/ErrorMessage.java +++ b/6thSeminar/springPractice/src/main/java/org/sopt/springPractice/common/dto/ErrorMessage.java @@ -11,7 +11,7 @@ public enum ErrorMessage { MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "ID에 해당하는 사용자가 존재하지 않습니다."), BLOG_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "ID에 해당하는 블로그가 존재하지 않습니다."), JWT_UNAUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED.value(), "사용자의 로그인 검증을 실패했습니다."), - REFRESH_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "refresh token이 존재하지 않습니다."); + EXPIRED_JWT_TOKEN(HttpStatus.UNAUTHORIZED.value(), "만료된 refresh 토큰입니다."); private final int status; private final String message; }