Skip to content

Commit

Permalink
🐛 Fix : 리프레시 토큰 무조건 access Token과 재발급 되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
CYY1007 committed Feb 16, 2024
1 parent ad6a448 commit 0f9bfe4
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RefreshToken generateRefreshToken(String socialId, SocialType socialType)

LocalDateTime currentTime = LocalDateTime.now();

LocalDateTime expireTime = currentTime.plus(1000, ChronoUnit.MINUTES);
LocalDateTime expireTime = currentTime.plus(90, ChronoUnit.SECONDS);

return refreshTokenRepository.save(
RefreshToken.builder()
Expand All @@ -68,8 +68,6 @@ public RefreshToken reGenerateRefreshToken(MemberRequest.ReissueDTO request) {
() -> new RefreshTokenException(ErrorCode.INVALID_REFRESH_TOKEN));
LocalDateTime expireTime = findRefreshToken.getExpireTime();
LocalDateTime current = LocalDateTime.now();
// 테스트용, 실제로는 현재 시간 + accessToken 만료 시간
LocalDateTime expireDeadLine = current.plusSeconds(20);

Member member =
memberRepository
Expand All @@ -80,13 +78,8 @@ public RefreshToken reGenerateRefreshToken(MemberRequest.ReissueDTO request) {
logger.error("이미 만료된 리프레시 토큰 발견");
throw new RefreshTokenException(ErrorCode.RELOGIN_EXCEPTION);
}

// 새로 발급할 accessToken보다 refreshToken이 먼저 만료 될 경우인가?
if (expireTime.isAfter(expireDeadLine)) {
logger.info("기존 리프레시 토큰 발급");
return findRefreshToken;
} else {
logger.info("accessToken보다 먼저 만료될 예정인 리프레시 토큰 발견");
else{
logger.info("리프레시 토큰과 access 토큰 재발급");
deleteRefreshToken(request.getRefreshToken());
return generateRefreshToken(member.getSocialId(), member.getSocialType());
}
Expand Down

0 comments on commit 0f9bfe4

Please sign in to comment.