diff --git a/src/main/java/com/tiki/server/auth/controller/AuthController.java b/src/main/java/com/tiki/server/auth/controller/AuthController.java index 0bea8c8e..722f4900 100644 --- a/src/main/java/com/tiki/server/auth/controller/AuthController.java +++ b/src/main/java/com/tiki/server/auth/controller/AuthController.java @@ -1,13 +1,15 @@ package com.tiki.server.auth.controller; import com.tiki.server.auth.dto.request.LoginRequest; -import com.tiki.server.auth.dto.response.SignInGetResponse; import com.tiki.server.auth.dto.response.ReissueGetResponse; import com.tiki.server.common.dto.SuccessResponse; import com.tiki.server.common.support.UriGenerator; +import com.tiki.server.member.dto.response.AccessTokenGetResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.val; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseCookie; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -22,16 +24,28 @@ @RequestMapping("api/v1/auth") public class AuthController { + @Value("${JWT.EXPIRE_REFRESH}") + private int COOKIE_MAX_AGE; + private final static String REFRESH_TOKEN = "refreshToken"; private final AuthService authService; @PostMapping("/sign-in") - public ResponseEntity> signIn( + public ResponseEntity> signIn( HttpServletResponse httpServletResponse, @RequestBody LoginRequest request ) { val response = authService.login(request, httpServletResponse); + ResponseCookie cookie = ResponseCookie.from(REFRESH_TOKEN, response.refreshToken()) + .maxAge(COOKIE_MAX_AGE) + .path("/") + .secure(true) + .sameSite("None") + .httpOnly(true) + .build(); + httpServletResponse.setHeader("Set-Cookie", cookie.toString()); return ResponseEntity.created(UriGenerator.getUri("/")) - .body(SuccessResponse.success(SUCCESS_SIGN_IN.getMessage(), response)); + .body(SuccessResponse.success(SUCCESS_SIGN_IN.getMessage(), + AccessTokenGetResponse.of(response.accessToken()))); } @GetMapping("/reissue")