-
Notifications
You must be signed in to change notification settings - Fork 2
[BE] [REFACTOR] JWT 클래스 유지보수성 향상 - JwtUtils 단일화 및 클레임 키 상수화 #252
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
The head ref may contain hidden characters: "20260215_#209_\uD1A0\uD070_\uAD00\uB828_\uC720\uC9C0\uBCF4\uC218\uC131_\uD5A5\uC0C1"
Changes from all commits
ce3bf9f
c24f0ec
686e44e
697b91f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,7 @@ | |
| import org.sejongisc.backend.activity.event.ActivityEvent; | ||
| import org.sejongisc.backend.common.auth.entity.RefreshToken; | ||
| import org.sejongisc.backend.common.auth.repository.RefreshTokenRepository; | ||
| import org.sejongisc.backend.common.auth.jwt.JwtParser; | ||
| import org.sejongisc.backend.common.auth.jwt.JwtProvider; | ||
| import org.sejongisc.backend.common.auth.jwt.JwtUtils; | ||
| import org.sejongisc.backend.common.exception.CustomException; | ||
| import org.sejongisc.backend.common.exception.ErrorCode; | ||
| import org.sejongisc.backend.user.entity.Role; | ||
|
|
@@ -29,8 +28,9 @@ public class AuthService { | |
|
|
||
| private final UserRepository userRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final JwtProvider jwtProvider; | ||
| private final JwtUtils jwtUtils; | ||
| private final RefreshTokenRepository refreshTokenRepository; | ||
|
|
||
| private final JwtParser jwtParser; | ||
| private final ApplicationEventPublisher eventPublisher; | ||
discipline24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
@@ -49,14 +49,14 @@ public AuthResponse login(AuthRequest request) { | |
| !passwordEncoder.matches(request.getPassword().trim(), user.getPasswordHash())) { | ||
| throw new CustomException(ErrorCode.UNAUTHORIZED); | ||
| } | ||
|
|
||
| String accessToken = jwtUtils.createToken(user.getUserId(), user.getRole(), user.getEmail()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이부분은 PENDING_MEMBER 검증 이전으로 올린 이유가 궁금합니다!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 그 부분은 제가 반영되기 전 코드에서 작업한 것 같아서 수정해야 할 것 같습니당 |
||
| String refreshToken = jwtUtils.createRefreshToken(user.getUserId()); | ||
|
|
||
| if (user.getRole().equals(Role.PENDING_MEMBER)) { | ||
| throw new CustomException(ErrorCode.NEED_PENDING_APPROVAL); | ||
| } | ||
|
|
||
| String accessToken = jwtProvider.createToken(user.getUserId(), user.getRole(), user.getEmail()); | ||
| String refreshToken = jwtProvider.createRefreshToken(user.getUserId()); | ||
|
|
||
| // 기존 토큰 삭제 후 새로 저장 | ||
| refreshTokenRepository.findByUserId(user.getUserId()) | ||
| .ifPresent(refreshTokenRepository::delete); | ||
|
|
@@ -89,7 +89,7 @@ public AuthResponse login(AuthRequest request) { | |
|
|
||
| @Transactional | ||
| public void logout(String accessToken) { | ||
| UUID userId = jwtParser.getUserIdFromToken(accessToken); | ||
| UUID userId = jwtUtils.getUserIdFromToken(accessToken); | ||
| refreshTokenRepository.deleteByUserId(userId); | ||
| log.info("로그아웃 완료: userId={}", userId); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.