Skip to content

Commit

Permalink
�fix: 로그아웃 API가 쿠키를 삭제하지 못하는 문제 수정 (#597)
Browse files Browse the repository at this point in the history
fix: 수정된 쿠키를 응답에 담아보내도록 수정
  • Loading branch information
uwoobeat authored Aug 11, 2024
1 parent 407b380 commit 5e48c4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CookieValue;
Expand All @@ -25,9 +26,10 @@ public class AuthController {
@GetMapping("/logout")
public ResponseEntity<Void> logout(
@CookieValue(ACCESS_TOKEN_COOKIE_NAME) Cookie accessToken,
@CookieValue(REFRESH_TOKEN_COOKIE_NAME) Cookie refreshToken) {
cookieUtil.deleteCookie(accessToken);
cookieUtil.deleteCookie(refreshToken);
@CookieValue(REFRESH_TOKEN_COOKIE_NAME) Cookie refreshToken,
HttpServletResponse response) {
cookieUtil.deleteCookie(accessToken, response);
cookieUtil.deleteCookie(refreshToken, response);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ private ResponseCookie generateTokenCookie(String cookieName, String tokenValue)
.build();
}

public void deleteCookie(jakarta.servlet.http.Cookie cookie) {
public void deleteCookie(jakarta.servlet.http.Cookie cookie, HttpServletResponse response) {
cookie.setPath("/");
cookie.setValue("");
cookie.setMaxAge(0);
response.addCookie(cookie);
}
}

0 comments on commit 5e48c4a

Please sign in to comment.