Skip to content

Commit

Permalink
#35 [Update] 네번째 시도
Browse files Browse the repository at this point in the history
쿠키가 삭제되지 않는 문제 해결하기
  • Loading branch information
Anna-Jin committed Jul 19, 2022
1 parent e1c7b82 commit dddd6d9
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/main/java/com/mpnp/baechelin/util/CookieUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ public static Optional<Cookie> getCookie(HttpServletRequest request, String name

// 쿠키 생성
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
ResponseCookie cookie = ResponseCookie.from(name, value)
.domain(".bae-chelin.com")
.path("/")
.httpOnly(true)
.maxAge(maxAge)
.secure(true)
.sameSite("None")
.build();

response.addHeader("Set-Cookie", cookie.toString());
// Cookie cookie = new Cookie(name, value);
//
// cookie.setPath("/");
// cookie.setHttpOnly(true); // XSS 공격을 막기 위한 설정
// cookie.setMaxAge(maxAge);
// cookie.setSecure(true);
// ResponseCookie cookie = ResponseCookie.from(name, value)
// .domain(".bae-chelin.com")
// .path("/")
// .httpOnly(true)
// .maxAge(maxAge)
// .secure(true)
// .sameSite("None")
// .build();
//
// response.addCookie(cookie);
// response.addHeader("Set-Cookie", cookie.toString());
Cookie cookie = new Cookie(name, value);

cookie.setPath("/");
cookie.setHttpOnly(true); // XSS 공격을 막기 위한 설정
cookie.setMaxAge(maxAge);
cookie.setDomain(".bae-chelin.com");

response.addCookie(cookie);
}

// 쿠키 삭제
Expand All @@ -59,6 +59,7 @@ public static void deleteCookie(HttpServletRequest request, HttpServletResponse
cookie.setPath("/");
cookie.setMaxAge(0);
cookie.setSecure(false);
cookie.setDomain("");

response.addCookie(cookie);
}
Expand Down

0 comments on commit dddd6d9

Please sign in to comment.