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

[BE] 토큰 관련 코드를 리팩토링한다. #754

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

JINU-CHANG
Copy link
Contributor

❗ Issue

✨ 구현한 기능

  • 토큰 에러 메시지 적용

    • 액세스 토큰과 리프레시 토큰의 에러 메시지를 다르게 하기 위해 리팩토링을 진행했습니다.
  • TODO로 남겨둔 부분 리팩토링

    • 토큰이 존재하는지 검증하는 부분이 1) null 체크, 2) 토큰 유무 체크 이렇게 if문내에 존재했는데 실수하기 쉬운 코드라고 생각했습니다. 하나의 메소드에서 검증이 가능하도록 리팩토링했습니다.
// TODO 리팩토링 전
if (request.getCookies() == null || cookieResolver.isTokenNotExist(request.getCookies())) {
    throw new BangggoodException(ExceptionCode.AUTHENTICATION_TOKEN_EMPTY);
}

// 리팩토링 후
public void checkLoginRequired(HttpServletRequest request) {
      if (isTokenEmpty(request)) {
          throw new BangggoodException(ExceptionCode.AUTHENTICATION_TOKEN_EMPTY);
      }

      if (isRefreshTokenEmpty(request.getCookies())) {
          throw new BangggoodException(ExceptionCode.AUTHENTICATION_REFRESH_TOKEN_EMPTY);
      }
  }
  • RefreshToken이 도입되면서 JwtTokenProvider의 책임이 많아져 JwtTokenResolver를 생성하고 역할을 분리했습니다.

📢 논의하고 싶은 내용

🎸 기타

  • 이외 작업하면서 no-usage인 코드 제거했습니다.

Copy link
Contributor

@shin-jisong shin-jisong left a comment

Choose a reason for hiding this comment

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

잘 구현해 주셔서 특별한 코멘트 사항이 없네요
수고하셨습니다~!

@@ -82,4 +85,34 @@ void resolveAuthPrincipalArgument_throwException_whenTokenEmpty() {
.statusCode(401)
.body("message", containsString(ExceptionCode.AUTHENTICATION_TOKEN_EMPTY.getMessage()));
}

@DisplayName("@AuthPrinciapl 어노테이션 동작 성공 : 액세스 토큰 존재 X, 리프레시 토큰 존재 O 일때 예외를 발생시킨다.")
Copy link
Contributor

Choose a reason for hiding this comment

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

소소하지만 다른 테스트는 문장형이 아니었던 것 같아요!

Copy link
Contributor

@tkdgur0906 tkdgur0906 left a comment

Choose a reason for hiding this comment

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

깔끔하게 잘 짜주셨네요~
고생하셨습니다~

Copy link
Contributor

@tsulocalize tsulocalize left a comment

Choose a reason for hiding this comment

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

even하게 코드가 짜여있네요. 합격입니다.

@tsulocalize tsulocalize merged commit 562f36d into dev-be Oct 7, 2024
2 checks passed
@tsulocalize tsulocalize deleted the refactor/747-token branch October 7, 2024 07:56
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.

4 participants