diff --git a/src/main/java/com/listywave/auth/application/domain/JwtManager.java b/src/main/java/com/listywave/auth/application/domain/JwtManager.java index dc2727a4..7ba570b7 100644 --- a/src/main/java/com/listywave/auth/application/domain/JwtManager.java +++ b/src/main/java/com/listywave/auth/application/domain/JwtManager.java @@ -1,7 +1,7 @@ package com.listywave.auth.application.domain; import static com.listywave.common.exception.ErrorCode.REQUIRED_ACCESS_TOKEN; -import static java.util.concurrent.TimeUnit.MINUTES; +import static java.util.concurrent.TimeUnit.HOURS; import com.listywave.common.exception.CustomException; import io.jsonwebtoken.Jwts; @@ -14,7 +14,7 @@ public class JwtManager { private static final SecretKey key = Jwts.SIG.HS256.key().build(); - private static final Long ACCESS_TOKEN_VALID_MILLISECOND = MINUTES.toMillis(30); + private static final Long ACCESS_TOKEN_VALID_MILLISECOND = HOURS.toMillis(8); public String createToken(Long userId) { Date now = new Date(); diff --git a/src/main/java/com/listywave/auth/application/dto/LoginResponse.java b/src/main/java/com/listywave/auth/application/dto/LoginResponse.java index 4467282b..014e4943 100644 --- a/src/main/java/com/listywave/auth/application/dto/LoginResponse.java +++ b/src/main/java/com/listywave/auth/application/dto/LoginResponse.java @@ -10,10 +10,11 @@ public record LoginResponse( String description, int followingCount, int followerCount, - boolean isFirst + boolean isFirst, + String accessToken ) { - public static LoginResponse of(User user, boolean isFirst) { + public static LoginResponse of(User user, boolean isFirst, String accessToken) { return new LoginResponse( user.getId(), user.getProfileImageUrl(), @@ -22,7 +23,8 @@ public static LoginResponse of(User user, boolean isFirst) { user.getDescription(), user.getFollowingCount(), user.getFollowerCount(), - isFirst + isFirst, + accessToken ); } } diff --git a/src/main/java/com/listywave/auth/application/service/AuthService.java b/src/main/java/com/listywave/auth/application/service/AuthService.java index 78334f47..b4aa26e9 100644 --- a/src/main/java/com/listywave/auth/application/service/AuthService.java +++ b/src/main/java/com/listywave/auth/application/service/AuthService.java @@ -35,12 +35,12 @@ public LoginResponse login(String authCode) { if (foundUser.isEmpty()) { User user = User.initialCreate(kakaoMember.id(), kakaoMember.kakaoAccount().email()); User createdUser = userRepository.save(user); - return LoginResponse.of(createdUser, true); + return LoginResponse.of(createdUser, true, createTokenBy(createdUser.getId())); } - return LoginResponse.of(foundUser.get(), false); + return LoginResponse.of(foundUser.get(), false, createTokenBy(foundUser.get().getId())); } - public String createToken(Long userId) { + private String createTokenBy(Long userId) { return jwtManager.createToken(userId); } } diff --git a/src/main/java/com/listywave/auth/presentation/controller/AuthController.java b/src/main/java/com/listywave/auth/presentation/controller/AuthController.java index b95a2052..ebf42a7a 100644 --- a/src/main/java/com/listywave/auth/presentation/controller/AuthController.java +++ b/src/main/java/com/listywave/auth/presentation/controller/AuthController.java @@ -5,7 +5,6 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -21,21 +20,13 @@ public class AuthController { @GetMapping("/auth/kakao") ResponseEntity redirectAuthCodeRequestUrl(HttpServletResponse response) throws IOException { String requestUrl = authService.provideRedirectUri(); - response.sendRedirect(requestUrl); return ResponseEntity.status(HttpStatus.FOUND).build(); } @GetMapping("/auth/redirect/kakao") - ResponseEntity login( - @RequestParam(name = "code") String authCode, - HttpServletResponse response - ) { + ResponseEntity login(@RequestParam(name = "code") String authCode) { LoginResponse loginResponse = authService.login(authCode); - - String accessToken = authService.createToken(loginResponse.id()); - - response.setHeader(HttpHeaders.SET_COOKIE, accessToken); return ResponseEntity.ok(loginResponse); } }