Skip to content

Commit

Permalink
fix: OAuth2LoginSuccessHandler에서 회원가입 여부 확인 시 socialType, authId로 판별하…
Browse files Browse the repository at this point in the history
…도록 변경
  • Loading branch information
bflykky committed Aug 6, 2024
1 parent 4cb3215 commit 229b952
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,8 @@ public ResultResponse<LoginInfo> login(@Valid @RequestBody LoginRequest request)
}

@GetMapping("/check-registration")
@Operation(summary = "회원가입 여부 조회 API", description = "이메일을 통해, 해당 이메일을 가진 회원의 가입 여부를 조회하는 API입니다.")
@Parameters(value = {
@Parameter(name = "email", description = "회원가입 여부를 확인할 이메일을 입력해 주세요.")
})
public ResultResponse<CheckMemberRegistration> checkSignup(@RequestParam("email") @Valid @Email String email) {
return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(email));
@Operation(summary = "회원가입 여부 조회 API", description = "authId와 플랫폼명을 통해, 해당 정보와 일치하는 회원의 가입 여부를 조회하는 API입니다.")
public ResultResponse<CheckMemberRegistration> checkSignup(@Valid @RequestBody LoginRequest request) {
return ResultResponse.of(CHECK_MEMBER_REGISTRATION, memberService.checkRegistration(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}

0 comments on commit 229b952

Please sign in to comment.