Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 토큰 재발급 시 JWT 토큰 예외 처리 #89

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.kkumulkkum.server.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.kkumulkkum.server.annotation.UserId;
import org.kkumulkkum.server.constant.AuthConstant;
Expand All @@ -20,7 +20,7 @@ public class AuthController {

@PostMapping("/v1/auth/signin")
public ResponseEntity<UserTokenDto> signin(
@NotNull @RequestHeader(AuthConstant.AUTHORIZATION_HEADER) final String providerToken,
@NotBlank @RequestHeader(AuthConstant.AUTHORIZATION_HEADER) final String providerToken,
@Valid @RequestBody final UserLoginDto userLoginDto
) {
return ResponseEntity.ok(authService.signin(providerToken, userLoginDto));
Expand All @@ -37,7 +37,7 @@ public ResponseEntity<Void> signout(

@PostMapping("/v1/auth/reissue")
public ResponseEntity<JwtTokenDto> reissue(
@NotNull @RequestHeader(AuthConstant.AUTHORIZATION_HEADER) final String refreshToken
@NotBlank @RequestHeader(AuthConstant.AUTHORIZATION_HEADER) final String refreshToken
) {
return ResponseEntity.ok(authService.reissue(refreshToken));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum AuthErrorCode implements DefaultErrorCode {
EXPIRED_APPLE_IDENTITY_TOKEN(HttpStatus.BAD_REQUEST, 40014, "Apple Identity Token 유효기간이 만료됐습니다."),
// 401 UNAUTHORIZED
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, 40110, "인증되지 않은 사용자입니다."),
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, 40111, "액세스 토큰의 형식이 올바르지 않습니다."),
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, 40111, "올바르지 않은 토큰입니다."),
EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, 40112, "액세스 토큰이 만료되었습니다."),
UNSUPPORTED_TOKEN(HttpStatus.UNAUTHORIZED, 40113, "지원하지 않는 토큰 형식입니다."),
EMPTY_TOKEN(HttpStatus.UNAUTHORIZED, 40114, "토큰이 제공되지 않았습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public void signout(final Long userId) {

@Transactional
public JwtTokenDto reissue(final String refreshToken) {
Long userId = jwtTokenProvider.getUserIdFromJwt(refreshToken);
Long userId;
try{
userId = jwtTokenProvider.getUserIdFromJwt(refreshToken);
} catch (Exception e) {
throw new AuthException(AuthErrorCode.INVALID_TOKEN);
}
Token token = tokenRetriever.findByRefreshToken(refreshToken);

if(!userId.equals(token.getId())) {
Expand Down
Loading