Skip to content

Commit

Permalink
fix: #103 refresh token error 처리 수정 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarmaPol authored Mar 21, 2024
1 parent 8807d7a commit b9102aa
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class RedisRefreshTokenRepository(val redisTemplate: RedisTemplate<String, Any>)
}

fun findByRefreshToken(refreshToken: String): Long? {
return redisTemplate.opsForValue().get(refreshToken).toString().toLong()
val memberId = redisTemplate.opsForValue().get(refreshToken) ?: return null
return memberId.toString().toLong()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class ApiErrorCode(
ACCESS_TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED, "ACCESS_TOKEN_EXPIRED", "어세스 토큰이 만료되었으니 재발급 해주세요"),
ACCESS_TOKEN_MALFORMED(HttpStatus.UNAUTHORIZED, "ACCESS_TOKEN_MALFORMED", "올바르지 않은 토큰입니다."),
ACCESS_DENIED(HttpStatus.FORBIDDEN, "ACCESS_DENIED", "접근이 거부되었습니다."),
REFRESH_TOKEN_NOT_FOUND_MEMBER(HttpStatus.UNAUTHORIZED, "REFRESH_TOKEN_NOT_FOUND_MEMBER", "리프레시 토큰을 재발급 할수 없습니다. 존재하지 않는 회원입니다."),

// common
BAD_REQUEST(HttpStatus.BAD_REQUEST, "BAD_REQUEST", "잘못된 요청입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AuthService(
val memberId = redisRefreshTokenRepository.findByRefreshToken(refreshTokenRequest.refreshToken)
?: throw ApiException(ApiErrorCode.REFRESH_TOKEN_EXPIRED)
val member = memberRepository.findByIdOrNull(memberId)
?: throw ApiException(ApiErrorCode.NOT_FOUND_MEMBER)
?: throw ApiException(ApiErrorCode.REFRESH_TOKEN_NOT_FOUND_MEMBER)

val oauth2UserDetails = createOauth2UserDetails(member)
val accessToken = jwtTokenProvider.generateAccessToken(oauth2UserDetails)
Expand Down

0 comments on commit b9102aa

Please sign in to comment.