From 229b952094900dd4b5a9a9b80d08e03717048581 Mon Sep 17 00:00:00 2001 From: bflykky Date: Tue, 6 Aug 2024 22:28:23 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20OAuth2LoginSuccessHandler=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=ED=99=95=EC=9D=B8=20=EC=8B=9C=20socialType,=20auth?= =?UTF-8?q?Id=EB=A1=9C=20=ED=8C=90=EB=B3=84=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/AuthController.java | 9 ++-- .../domain/member/service/MemberService.java | 9 ++-- .../member/service/MemberServiceImpl.java | 45 +++++++++---------- .../handler/OAuth2LoginSuccessHandler.java | 2 +- .../security/model/CustomOAuth2User.java | 9 +++- 5 files changed, 35 insertions(+), 39 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 62c02d98..9a60aa71 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 @@ -63,11 +63,8 @@ public ResultResponse login(@Valid @RequestBody LoginRequest request) } @GetMapping("/check-registration") - @Operation(summary = "회원가입 여부 조회 API", description = "이메일을 통해, 해당 이메일을 가진 회원의 가입 여부를 조회하는 API입니다.") - @Parameters(value = { - @Parameter(name = "email", description = "회원가입 여부를 확인할 이메일을 입력해 주세요.") - }) - public ResultResponse checkSignup(@RequestParam("email") @Valid @Email String email) { - return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(email)); + @Operation(summary = "회원가입 여부 조회 API", description = "authId와 플랫폼명을 통해, 해당 정보와 일치하는 회원의 가입 여부를 조회하는 API입니다.") + public ResultResponse checkSignup(@Valid @RequestBody LoginRequest request) { + return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(request)); } } 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 880bf63f..da9cca45 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,12 +10,11 @@ import com.umc.naoman.domain.member.entity.SocialType; public interface MemberService { - Member findMember(Long memberId); - Member findMember(String email); - Member findMember(String authId, SocialType socialType); - CheckMemberRegistration checkRegistration(LoginRequest request); - LoginInfo signup(SignupRequest request); LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request); + LoginInfo signup(SignupRequest request); LoginInfo login(LoginRequest request); + CheckMemberRegistration checkRegistration(LoginRequest request); MemberInfo getMyInfo(Member member); + Member findMember(Long memberId); + Member findMember(SocialType socialType, String authId); } 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 a596b592..0244e14c 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 @@ -34,30 +34,6 @@ public class MemberServiceImpl implements MemberService { @Value("${jwt.refresh-token-validity-in-seconds}") private Long REFRESH_TOKEN_VALIDITY_IN_SECONDS; - @Override - public Member findMember(Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID)); - } - - @Override - public Member findMember(String email) { - return memberRepository.findByEmail(email) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_EMAIL)); - } - - @Override - public Member findMember(String authId, SocialType socialType) { - return memberRepository.findByAuthIdAndSocialType(authId, socialType) - .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE)); - } - - @Override - public CheckMemberRegistration checkRegistration(LoginRequest request) { - boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId()); - return new CheckMemberRegistration(isRegistered); - } - @Override @Transactional public LoginInfo signup(SignupRequest request) { @@ -90,7 +66,7 @@ public LoginInfo signup(String tempMemberInfo, MarketingAgreedRequest request) { @Override public LoginInfo login(LoginRequest request) { - Member member = findMember(request.getAuthId(), request.getSocialType()); + Member member = findMember(request.getSocialType(), request.getAuthId()); Long memberId = member.getId(); String email = member.getEmail(); @@ -102,8 +78,27 @@ public LoginInfo login(LoginRequest request) { return memberConverter.toLoginInfo(memberId, accessToken, refreshToken); } + @Override + public CheckMemberRegistration checkRegistration(LoginRequest request) { + boolean isRegistered = memberRepository.existsBySocialTypeAndAuthId(request.getSocialType(), request.getAuthId()); + return new CheckMemberRegistration(isRegistered); + } + @Override public MemberInfo getMyInfo(Member member) { return memberConverter.toMemberInfo(member); } + + @Override + public Member findMember(Long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_MEMBER_ID)); + } + + @Override + public Member findMember(SocialType socialType, String authId) { + return memberRepository.findByAuthIdAndSocialType(authId, socialType) + .orElseThrow(() -> new BusinessException(MEMBER_NOT_FOUND_BY_AUTH_ID_AND_SOCIAL_TYPE)); + } + } diff --git a/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java b/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java index a122b703..1673b05a 100644 --- a/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java +++ b/src/main/java/com/umc/naoman/global/security/handler/OAuth2LoginSuccessHandler.java @@ -49,7 +49,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal(); try { // 이미 회원가입된 회원인 경우 - Member member = memberService.findMember(oAuth2User.getEmail()); + Member member = memberService.findMember(oAuth2User.getProvider(), oAuth2User.getAuthId()); handleExistingMemberLogin(request, response, oAuth2User, member); } catch (BusinessException e) { // 회원가입되어 있지 않은 경우 handleMemberSignup(request, response, oAuth2User.getOAuthAttribute()); diff --git a/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java b/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java index 2d648620..2b3368d9 100644 --- a/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java +++ b/src/main/java/com/umc/naoman/global/security/model/CustomOAuth2User.java @@ -1,5 +1,6 @@ package com.umc.naoman.global.security.model; +import com.umc.naoman.domain.member.entity.SocialType; import com.umc.naoman.global.security.attribute.OAuthAttribute; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.oauth2.core.user.DefaultOAuth2User; @@ -20,7 +21,11 @@ public OAuthAttribute getOAuthAttribute() { return oAuthAttribute; } - public String getEmail() { - return this.oAuthAttribute.getEmail(); + public SocialType getProvider() { + return this.oAuthAttribute.getProvider(); + } + + public String getAuthId() { + return this.oAuthAttribute.getAuthId(); } }