From 98302daf60200b57202ec50e90dde7e16ac7e0f0 Mon Sep 17 00:00:00 2001 From: bflykky Date: Wed, 21 Aug 2024 22:22:37 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9B=B9=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=8B=9C=20=EC=BF=A0=ED=82=A4=EB=A1=9C=EB=8F=84=20?= =?UTF-8?q?access=20token,=20refresh=20token=20=EC=A0=84=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 프론트의 요청에 따라 임의로 respone body에 이어서, 쿠키로도 토큰을 전달한다. --- .../naoman/domain/member/controller/AuthController.java | 6 ++++-- .../umc/naoman/domain/member/service/MemberService.java | 3 ++- .../naoman/domain/member/service/MemberServiceImpl.java | 9 +++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java b/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java index c886655..5b9b009 100644 --- a/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java +++ b/src/main/java/com/umc/naoman/domain/member/controller/AuthController.java @@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.Email; import lombok.RequiredArgsConstructor; @@ -43,12 +44,13 @@ public class AuthController { hidden = true, in = ParameterIn.COOKIE) }) public ResultResponse signup(@CookieValue(value = "temp-member-info", required = false) Cookie tempMemberInfoCookie, - @Valid @RequestBody MarketingAgreedRequest request) { + @Valid @RequestBody MarketingAgreedRequest request, + HttpServletResponse response) { // 추후에 핸들러 처리로 바꿀까 생각 중 if (tempMemberInfoCookie == null) { throw new BusinessException(TEMP_MEMBER_INFO_COOKIE_NOT_FOUND); } - return ResultResponse.of(SIGNUP, memberService.signup(tempMemberInfoCookie.getValue(), request)); + return ResultResponse.of(SIGNUP, memberService.signup(tempMemberInfoCookie.getValue(), request, response)); } @PostMapping("/signup/android") diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java index fef068e..d57dfd6 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberService.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberService.java @@ -10,9 +10,10 @@ import com.umc.naoman.domain.member.dto.MemberResponse.MemberInfo; import com.umc.naoman.domain.member.entity.Member; import com.umc.naoman.domain.member.entity.SocialType; +import jakarta.servlet.http.HttpServletResponse; public interface MemberService { - LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request); + LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request, HttpServletResponse response); LoginInfo signup(SignupRequest request); LoginInfo login(LoginRequest request); CheckMemberRegistration checkRegistration(LoginRequest request); diff --git a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java index d02f5c8..e39385b 100644 --- a/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/member/service/MemberServiceImpl.java @@ -19,8 +19,10 @@ import com.umc.naoman.domain.shareGroup.entity.Role; import com.umc.naoman.domain.shareGroup.service.ShareGroupService; import com.umc.naoman.global.error.BusinessException; +import com.umc.naoman.global.security.util.CookieUtils; import com.umc.naoman.global.security.util.JwtUtils; import io.jsonwebtoken.Claims; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -49,11 +51,14 @@ public class MemberServiceImpl implements MemberService { @Override @Transactional - public LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request) { + public LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request, HttpServletResponse response) { Claims payload = jwtUtils.getPayload(tempMemberInfo); SignupRequest signupRequest = memberConverter.toSignupRequest(payload, request.getMarketingAgreed()); - return signup(signupRequest); + LoginInfo loginInfo = signup(signupRequest); + CookieUtils.addCookie(response, "access-token", loginInfo.getAccessToken(), ACCESS_TOKEN_VALIDITY_IN_SECONDS.intValue()); + CookieUtils.addCookie(response, "refresh-token", loginInfo.getRefreshToken(), REFRESH_TOKEN_VALIDITY_IN_SECONDS.intValue()); + return loginInfo; } @Override