Skip to content

Commit

Permalink
feat: set-cookie Domain 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
smartandhandsome committed Mar 10, 2024
1 parent 47522ec commit f14ff74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import coffeemeet.server.report.service.dto.ReportDetailDto;
import coffeemeet.server.report.service.dto.ReportListDto;
import coffeemeet.server.report.service.dto.ReportSummary;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import java.util.List;
Expand Down Expand Up @@ -61,12 +63,20 @@ public class AdminController {
@PostMapping("/login")
public ResponseEntity<Void> login(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
@Valid @RequestBody AdminLoginHTTP.Request request
) {
adminService.login(request.id(), request.password());
HttpSession session = httpServletRequest.getSession();
session.setAttribute(ADMIN_SESSION_ATTRIBUTE, request.id());
session.setMaxInactiveInterval(1800);

Cookie sessionCookie = new Cookie("JSESSIONID", session.getId());
sessionCookie.setPath("/");
sessionCookie.setHttpOnly(true);
sessionCookie.setSecure(true);
sessionCookie.setDomain(".coffee-meet.com");
httpServletResponse.addCookie(sessionCookie);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void loginTest() throws Exception {

@Test
@DisplayName("관리자 로그아웃 할 수 있다.")
void name() throws Exception {
void logoutTest() throws Exception {
// given, when, then
mockMvc.perform(post(baseUrl + "/logout")
.header(JSESSION, SESSION_VALUE)
Expand Down

0 comments on commit f14ff74

Please sign in to comment.