|
18 | 18 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; |
19 | 19 |
|
20 | 20 | import java.io.IOException; |
| 21 | +import java.util.List; |
21 | 22 | import java.util.Map; |
22 | | -import java.util.Optional; |
23 | 23 | import java.util.concurrent.ConcurrentHashMap; |
24 | 24 |
|
25 | 25 | @Slf4j |
@@ -48,10 +48,14 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ |
48 | 48 |
|
49 | 49 | Object loginLock = LOGIN_LOCKS.computeIfAbsent(googleUserId, key -> new Object()); |
50 | 50 | synchronized (loginLock) { |
51 | | - Optional<User> existingUser = userRepository.findBySocialTypeAndSocialId(SocialType.GOOGLE, googleUserId); |
52 | | - |
53 | | - if (existingUser.isPresent()) { |
54 | | - return googleLoginService.handleLogin(oAuthGoogleRequestDto, existingUser.get(), response); |
| 51 | + List<User> existingUsers = userRepository.findAllBySocialTypeAndSocialIdOrderByIdDesc(SocialType.GOOGLE, googleUserId); |
| 52 | + |
| 53 | + if (!existingUsers.isEmpty()) { |
| 54 | + if (existingUsers.size() > 1) { |
| 55 | + log.warn("동일한 Google socialId를 가진 유저가 {}명 존재합니다. 최신 userId={} 계정으로 로그인합니다.", |
| 56 | + existingUsers.size(), existingUsers.get(0).getId()); |
| 57 | + } |
| 58 | + return googleLoginService.handleLogin(oAuthGoogleRequestDto, existingUsers.get(0), response); |
55 | 59 | } else { |
56 | 60 | OAuthGoogleUserDto oAuthGoogleUserDto = new OAuthGoogleUserDto(googleUserId, (String) googlePayload.get("name"), (String) googlePayload.get("picture"), googlePayload.getEmail()); |
57 | 61 | return googleLoginService.handleRegister(oAuthGoogleRequestDto, oAuthGoogleUserDto, response); |
|
0 commit comments