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

[FEAT] JWT 재발급 API - #54 #56

Merged
merged 11 commits into from
Jul 11, 2024
Merged

[FEAT] JWT 재발급 API - #54 #56

merged 11 commits into from
Jul 11, 2024

Conversation

sjk4618
Copy link
Member

@sjk4618 sjk4618 commented Jul 10, 2024

🔥Pull requests

⛳️ 작업한 브랜치

👷 작업한 내용

  • RefreshToken 재발급
@Transactional
    public UserJwtInfoRes reissue(final String refreshToken) {
        RefreshToken foundRefreshToken = getRefreshTokenByToken(refreshToken);
        jwtProvider.validateRefreshToken(foundRefreshToken.getExpiredAt());
        Long userId = foundRefreshToken.getUserId();
        Token newToken = jwtProvider.issueToken(userId);
        return UserJwtInfoRes.of(userId, newToken.accessToken(), newToken.refreshToken());
    }
  • 토큰 만료기간 체크
    //refreshToken 재발급할 때 검증
    public void validateRefreshToken(LocalDateTime expireDate) {
        if (expireDate.isBefore(LocalDateTime.now())) {
            throw new UnauthorizedException(FailureCode.EXPIRED_REFRESH_TOKEN);
        }
    }

📟 관련 이슈

Copy link

@yummygyudon yummygyudon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오랜만에 앱잼단 리뷰하니까 재밌네요!!
서버 전향하셔서 고생이 많으실텐데 항상 응원합니다! 잘하고 계세요! ❤️

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjk4618
패키징을 authuser 로 분리하신 것 같아요!
다만 조금 의아했던 것은
AuthService.java의 경우, user 패키지 내에 위치하고 있고
인증(auth) API는 UserController.java 안에 구현되어있는 것 같아요!!

혼재시켜놓은 이유가 있을까요?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음에 폴더링할 때, auth관련도 user에 다 넣으려고 했는데, 분리하는게 좋을 것 같습니다.
추후에 열려있는 브랜치들 머지하고 변경하도록 하겠습니다

Comment on lines +22 to +31
public ResponseEntity<UserJwtInfoRes> signUp(@RequestHeader(AUTHORIZATION) final String token,
@RequestBody final UserSignUpReq userSignUPReq) {
UserJwtInfoRes userSignUpRes = authService.signUp(token, userSignUPReq);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(userSignUpRes);
}

@PostMapping("/signin")
public ResponseEntity<UserSignInRes> signIn(@RequestHeader(AUTHORIZATION) final String token,
public ResponseEntity<UserJwtInfoRes> signIn(@RequestHeader(AUTHORIZATION) final String token,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 Response DTO 이름이 UserSignInRes로 훨씬 직관적인 것 같아요!
DTO의 이름을 행위(기능)에 초점을 맞출 것인지, 내용에 초점 맞출 것인지 일관된 결정을 하면 더 좋을 것 같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 다시보니 로그인, 회원가입, jwt재발급에서 모두 같은 값을 주기때문에, 저렇게 하나로 사용했습니다

Comment on lines 145 to 148
log.error(e.getMessage());
throw new UnauthorizedException(FailureCode.INVALID_REFRESH_TOKEN_VALUE);
} catch (Exception e) {
log.info(e.getMessage());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException 에 대해서는 log.error 를 찍으시구
Exception에 대해서는 log.info를 찍으신 이유가 따로 있을까요?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아 error로 바꾸겠습니다.

throw new UnauthorizedException(FailureCode.INVALID_REFRESH_TOKEN_VALUE);
} catch (Exception e) {
log.info(e.getMessage());
throw new RuntimeException("An unexpected error occurred", e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어플리케이션 Custom Exception 클래스를 구현했고 해당 Custom Exception에서도 RuntimeException 상속받은 것 같아요!
그렇기 때문에 굳이 RuntimeException 객체를 throw 한 이유가 궁금합니다!!

그리고 Message 값은 매직 String(private static String) 변수로 선언하고 주입시켜주면 훨씬 직관적일 것 같습니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 저희가 커스텀한 exception으로 throw 하겠습니다

sjk4618 added 2 commits July 11, 2024 22:18
# Conflicts:
#	dateroad-api/src/main/java/org/dateroad/user/api/UserController.java
#	dateroad-api/src/main/java/org/dateroad/user/service/AuthService.java
#	dateroad-external/src/main/java/org/dateroad/feign/kakao/KakaoPlatformUserIdProvider.java
Copy link
Member

@rlarlgnszx rlarlgnszx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

@sjk4618 sjk4618 merged commit c5d46bd into develop Jul 11, 2024
1 check passed
@sjk4618 sjk4618 deleted the feature/#54 branch July 11, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] JWT 재발급 API
3 participants