diff --git a/motivoo-domain/src/main/java/sopt/org/motivoo/domain/auth/service/OauthService.java b/motivoo-domain/src/main/java/sopt/org/motivoo/domain/auth/service/OauthService.java index 3cb4922..01ee123 100644 --- a/motivoo-domain/src/main/java/sopt/org/motivoo/domain/auth/service/OauthService.java +++ b/motivoo-domain/src/main/java/sopt/org/motivoo/domain/auth/service/OauthService.java @@ -88,19 +88,24 @@ public LoginResult login(OauthTokenCommand tokenRequest) { OAuthPlatformMemberResult applePlatformMember = appleLoginService.getApplePlatformMember(tokenRequest.accessToken()); List userEntity = userRetriever.getUsersBySocialId(applePlatformMember.platformId()); + log.info("userEntity: {}", userEntity.size()); + + User user; //처음 로그인 하거나 탈퇴한 경우 -> 회원가입 - if (userEntity == null || isWithdrawn(userEntity)) { - User user = saveUser(null, applePlatformMember.platformId(), socialPlatform, tokenRequest, refreshToken); + if (userEntity.isEmpty() || isWithdrawn(userEntity)) { + user = saveUser(null, applePlatformMember.platformId(), socialPlatform, tokenRequest, refreshToken); + } + userEntity = userRetriever.getUsersBySocialId(applePlatformMember.platformId()); + user = userEntity.get(0); - //로그인 - updateRefreshToken(user, refreshToken); - String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(),null,null)); + //로그인 + updateRefreshToken(user, refreshToken); + String accessToken = jwtTokenProvider.createAccessToken(new UserAuthentication(user.getId(),null,null)); - boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user); - boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched(); + boolean isFinishedOnboarding = healthRetriever.existsHealthByUser(user); + boolean isMatched = user.getParentchild() != null && user.getParentchild().isMatched(); - return LoginResult.of(user, accessToken, refreshToken, isFinishedOnboarding, isMatched); - } + return LoginResult.of(user, accessToken, refreshToken, isFinishedOnboarding, isMatched); } throw new UserException(INVALID_SOCIAL_PLATFORM); }