Skip to content

Commit

Permalink
πŸ”§ chore: null λ°˜ν™˜ μˆ˜μ • 및 μ½”λ“œ 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
jun02160 committed Feb 29, 2024
1 parent 3f3fea8 commit f365283
Showing 1 changed file with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Map;

import static sopt.org.motivoo.domain.auth.config.jwt.JwtTokenProvider.getAuthenticatedUser;
import static sopt.org.motivoo.domain.user.entity.SocialPlatform.*;
import static sopt.org.motivoo.domain.user.exception.UserExceptionType.*;

@Slf4j
@Service
Expand All @@ -47,7 +49,7 @@ public LoginResult login(OauthTokenCommand tokenRequest) {
SocialPlatform socialPlatform = SocialPlatform.of(providerName);
String refreshToken = jwtTokenProvider.createRefreshToken();

if(socialPlatform.equals(SocialPlatform.KAKAO)){
if (socialPlatform.equals(KAKAO)) {
ClientRegistration provider = inMemoryRepository.findByRegistrationId(providerName);

User user = getUserProfile(providerName, tokenRequest, provider, refreshToken);
Expand All @@ -58,12 +60,12 @@ public LoginResult login(OauthTokenCommand tokenRequest) {
return LoginResult.of(user, accessToken, refreshToken);
}

else if(socialPlatform.equals(SocialPlatform.APPLE)){
if (socialPlatform.equals(APPLE)) {
OAuthPlatformMemberResult applePlatformMember = appleLoginService.getApplePlatformMember(tokenRequest.accessToken());

List<User> userEntity = userRetriever.getUsersBySocialId(applePlatformMember.platformId());
//처음 둜그인 ν•˜κ±°λ‚˜ νƒˆν‡΄ν•œ 경우 -> νšŒμ›κ°€μž…
if(userEntity==null || isWithdrawn(userEntity)){
if (userEntity == null || isWithdrawn(userEntity)) {
saveUser(null, applePlatformMember.platformId(), socialPlatform, tokenRequest, refreshToken);
}

Expand All @@ -72,7 +74,7 @@ else if(socialPlatform.equals(SocialPlatform.APPLE)){
String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(userEntity.get(0).getId(),null,null));
return LoginResult.of(userEntity.get(0), accessToken, refreshToken);
}
return null;
throw new UserException(INVALID_SOCIAL_PLATFORM);
}


Expand Down Expand Up @@ -107,22 +109,18 @@ private OAuth2UserInfo getOAuth2UserInfo(String providerName, Map<String, Object
if (providerName.equals("kakao")) {
return new KakaoUserProfile(userAttributes);
}
throw new UserException(UserExceptionType.INVALID_SOCIAL_PLATFORM);
throw new UserException(INVALID_SOCIAL_PLATFORM);
}

private SocialPlatform getSocialPlatform(String providerName) {
try {
switch (providerName){
case "kakao":
return SocialPlatform.KAKAO;
case "apple":
return SocialPlatform.APPLE;
default:
throw new UserException(UserExceptionType.INVALID_SOCIAL_PLATFORM);

}
}catch (FeignException e){
throw new UserException(UserExceptionType.INVALID_SOCIAL_PLATFORM);
return switch (providerName) {
case "kakao" -> KAKAO;
case "apple" -> APPLE;
default -> throw new UserException(INVALID_SOCIAL_PLATFORM);
};
} catch (FeignException e){
throw new UserException(INVALID_SOCIAL_PLATFORM);
}

}
Expand Down

0 comments on commit f365283

Please sign in to comment.