Skip to content

Commit f98a605

Browse files
committed
[FIX] 기존 리프레시 토큰이 존재할 경우 이를 삭제하고 새로 저장하도록 처리
1 parent d0cf18e commit f98a605

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/com/example/ai_tutor/domain/auth/application/AuthService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,22 @@ public ResponseEntity<?> signIn(SignInReq signInReq, @RequestHeader("Authorizati
148148
UsernamePasswordAuthenticationToken authentication =
149149
new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
150150
SecurityContextHolder.getContext().setAuthentication(authentication);
151+
151152
// 5. JWT 토큰 생성 및 refresh 저장
152153
TokenMapping tokenMapping = customTokenProviderService.createToken(authentication);
153154

155+
// 기존 토큰이 있으면 삭제
156+
tokenRepository.findByUserEmail(user.getEmail())
157+
.ifPresent(tokenRepository::delete);
158+
159+
// 새 토큰 저장
154160
Token token = Token.builder()
155161
.userEmail(user.getEmail())
156162
.refreshToken(tokenMapping.getRefreshToken())
157163
.build();
158164
tokenRepository.save(token);
159165

166+
160167
// 6. 응답 구성
161168
AuthRes authResponse = AuthRes.builder()
162169
.accessToken(tokenMapping.getAccessToken())

0 commit comments

Comments
 (0)