Skip to content

Commit 6b93799

Browse files
committed
fix: 토큰 재발급 수정
1 parent c7b81e7 commit 6b93799

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/main/java/com/example/log4u/common/oauth2/controller/OAuth2Controller.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public ResponseEntity<?> reissue(
3030
HttpServletRequest request,
3131
HttpServletResponse response
3232
) {
33-
// 쿠키가 없으면 바로 잘못된 요청 처리
33+
// 쿠키가 없으면 바로 401 (로그아웃)
3434
Cookie[] cookies = request.getCookies();
35-
// if (cookies == null || cookies.length == 0) {
36-
// return ResponseEntity
37-
// .badRequest()
38-
// .body("쿠키가 존재하지 않습니다.");
39-
// }
35+
if (cookies == null || cookies.length == 0) {
36+
return ResponseEntity
37+
.status(HttpStatus.UNAUTHORIZED)
38+
.body("쿠키가 존재하지 않습니다.");
39+
}
4040

4141
String refresh = null;
4242
String access = null;
@@ -57,6 +57,13 @@ public ResponseEntity<?> reissue(
5757
.body("리프레시 토큰이 존재하지 않습니다.");
5858
}
5959

60+
// DB에 리프레시 토큰 존재하는지 확인
61+
if (!refreshTokenService.existsByRefresh(refresh)) {
62+
return ResponseEntity
63+
.status(HttpStatus.UNAUTHORIZED)
64+
.body("이미 로그아웃된 사용자입니다.");
65+
}
66+
6067
// 리프레시 토큰 만료 여부 확인
6168
try {
6269
jwtUtil.isExpired(refresh);

src/main/java/com/example/log4u/common/oauth2/service/RefreshTokenService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ public void saveRefreshToken(String name, String refresh) {
3636
public void deleteRefreshToken(String refresh) {
3737
refreshTokenRepository.deleteByRefresh(refresh);
3838
}
39+
40+
public boolean existsByRefresh(String refresh) {
41+
return refreshTokenRepository.existsByRefresh(refresh);
42+
}
3943
}

0 commit comments

Comments
 (0)