Skip to content

Commit

Permalink
feat: 웹 회원가입 시 쿠키로도 access token, refresh token 전달
Browse files Browse the repository at this point in the history
프론트의 요청에 따라 임의로 respone body에 이어서, 쿠키로도 토큰을 전달한다.
  • Loading branch information
bflykky committed Aug 21, 2024
1 parent 0abf638 commit 98302da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,12 +44,13 @@ public class AuthController {
hidden = true, in = ParameterIn.COOKIE)
})
public ResultResponse<LoginInfo> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 98302da

Please sign in to comment.