diff --git a/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java b/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java index a2fc5f346..d6fa0c1e2 100644 --- a/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java +++ b/backend/src/main/java/kr/momo/controller/attendee/AttendeeController.java @@ -1,11 +1,12 @@ package kr.momo.controller.attendee; -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import kr.momo.service.attendee.AttendeeService; import kr.momo.service.attendee.dto.AttendeeLoginRequest; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.http.ResponseCookie; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,21 +21,21 @@ public class AttendeeController { private final AttendeeService attendeeService; @PostMapping("/api/v1/meetings/{uuid}/login") - public void login( - @PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request, HttpServletResponse response - ) { + public ResponseEntity login(@PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request) { String token = attendeeService.login(uuid, request); String path = String.format("/api/v1/meetings/%s/", uuid); - Cookie cookie = createCookie(token, path); - response.addCookie(cookie); + return ResponseEntity.ok() + .header(HttpHeaders.SET_COOKIE, createCookie(token, path)) + .build(); } - private Cookie createCookie(String value, String path) { - Cookie cookie = new Cookie(ACCESS_TOKEN, value); - cookie.setHttpOnly(true); - cookie.setSecure(true); - cookie.setPath(path); - return cookie; + private String createCookie(String value, String path) { + return ResponseCookie.from(ACCESS_TOKEN, value) + .httpOnly(true) + .secure(true) + .path(path) + .build() + .toString(); } }