Skip to content

Commit

Permalink
[HotFix] convert oauth2 member find logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Jeong committed Mar 9, 2024
1 parent bf17156 commit b2ba770
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +13,8 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

Optional<Member> findByEmail(String email);

Optional<Member> findByEmailAndAuthProvider(String email, AuthProvider authProvider);

Optional<Member> findByNickname(String nickname);

List<Member> findByNameAndBirthday(String name, LocalDate birthday);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Member> byEmail = memberRepository.findByEmail(oAuth2UserInfo.getEmail());
Optional<Member> 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);
}
Expand Down

0 comments on commit b2ba770

Please sign in to comment.