diff --git a/src/main/java/com/example/waggle/domain/member/repository/MemberRepository.java b/src/main/java/com/example/waggle/domain/member/repository/MemberRepository.java index 83a41910..1e970323 100644 --- a/src/main/java/com/example/waggle/domain/member/repository/MemberRepository.java +++ b/src/main/java/com/example/waggle/domain/member/repository/MemberRepository.java @@ -1,6 +1,7 @@ package com.example.waggle.domain.member.repository; import com.example.waggle.domain.member.entity.Member; +import com.example.waggle.global.security.oauth2.OAuth2UserInfoFactory.AuthProvider; import org.springframework.data.jpa.repository.JpaRepository; import java.time.LocalDate; @@ -12,6 +13,8 @@ public interface MemberRepository extends JpaRepository { Optional findByEmail(String email); + Optional findByEmailAndAuthProvider(String email, AuthProvider authProvider); + Optional findByNickname(String nickname); List findByNameAndBirthday(String name, LocalDate birthday); diff --git a/src/main/java/com/example/waggle/global/security/oauth2/CustomOAuth2UserService.java b/src/main/java/com/example/waggle/global/security/oauth2/CustomOAuth2UserService.java index afe795e9..31a63e5c 100644 --- a/src/main/java/com/example/waggle/global/security/oauth2/CustomOAuth2UserService.java +++ b/src/main/java/com/example/waggle/global/security/oauth2/CustomOAuth2UserService.java @@ -51,11 +51,8 @@ protected OAuth2User processOAuth2User(OAuth2UserRequest oAuth2UserRequest, OAut if (!StringUtils.hasText(oAuth2UserInfo.getEmail())) { throw new AuthenticationHandler(ErrorStatus.AUTH_OAUTH2_EMAIL_NOT_FOUND_FROM_PROVIDER); } - Optional byEmail = memberRepository.findByEmail(oAuth2UserInfo.getEmail()); + Optional byEmail = memberRepository.findByEmailAndAuthProvider(oAuth2UserInfo.getEmail(), authProvider); Member member = byEmail.orElseGet(() -> registerMember(authProvider, oAuth2UserInfo)); - if (!authProvider.equals(member.getAuthProvider())) { - throw new AuthenticationHandler(ErrorStatus.AUTH_PROVIDER_IS_NOT_MATCH); - } return CustomUserDetails.create(member); }