Skip to content

Commit

Permalink
Refresh Token 만료 시 ErrorMessage 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ckkim817 committed Jun 2, 2024
1 parent f7b1a3b commit 8806e9f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 8806e9f

Please sign in to comment.