Skip to content

Commit

Permalink
[CHORE] CookieGenerator 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
paragon0107 committed Aug 2, 2024
1 parent 5bab24e commit 6b794e6
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/main/java/com/tiki/server/auth/controller/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.tiki.server.auth.controller;

import com.tiki.server.auth.dto.request.LoginRequest;
import com.tiki.server.auth.dto.response.ReissueGetResponse;
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.CookieGenerator;
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.*;

Expand All @@ -24,9 +22,6 @@
@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")
Expand All @@ -35,17 +30,11 @@ public ResponseEntity<SuccessResponse<AccessTokenGetResponse>> signIn(
@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();
val cookie = CookieGenerator.setRefreshTokenToCookie(response.refreshToken());
httpServletResponse.setHeader("Set-Cookie", cookie.toString());
return ResponseEntity.created(UriGenerator.getUri("/"))
.body(SuccessResponse.success(SUCCESS_SIGN_IN.getMessage(),
AccessTokenGetResponse.of(response.accessToken())));
AccessTokenGetResponse.from(response.accessToken())));
}

@GetMapping("/reissue")
Expand Down

0 comments on commit 6b794e6

Please sign in to comment.