Skip to content

Commit

Permalink
쿠키생성
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeSung98 committed Nov 28, 2023
1 parent 7c858bf commit c46ec35
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import com.weather.user.util.JWTUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
@@ -36,9 +37,14 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

try {
String token = jwtUtil.generateToken(authUserDTO.getNickname());

String result = objectMapper.writeValueAsString(authUserDTO);
result = result.replace("}", ", \"token\": \"" + token + "\"}");

Cookie cookie = new Cookie("result", result);
cookie.setHttpOnly(true); // JavaScript를 통한 쿠키 접근을 막기 위해 사용
cookie.setMaxAge(7 * 24 * 60 * 60); // 쿠키의 만료 시간 설정 (예: 7일)
response.addCookie(cookie); // 응답에 쿠키 추가

response.setContentType("application/json;charset=utf-8");
response.getWriter().write(result);
} catch (Exception e) {

0 comments on commit c46ec35

Please sign in to comment.