Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 카카오 로그인 오류 수정 #4

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/com/kusitms/jipbap/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.kusitms.jipbap.user.Role;
import com.kusitms.jipbap.user.User;
import com.kusitms.jipbap.user.UserRepository;
import com.kusitms.jipbap.user.exception.UserNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -28,6 +29,7 @@
import org.springframework.web.client.RestTemplate;

import java.lang.reflect.Member;
import java.util.Optional;

@Slf4j
@Service
Expand Down Expand Up @@ -142,9 +144,7 @@ public SignInResponseDto kakaoAutoSignIn(KakaoProfileDto profile) {
.oauth(KAKAO)
.build();

User findUser = userRepository.findByEmail(kakaoUser.getEmail()).orElse(null);

if(findUser == null) {
if(userRepository.findByEmail(kakaoUser.getEmail()).isEmpty()) {
log.info(profile.getKakao_account().getEmail()+": 기존 회원이 아니므로 자동 회원가입 후 로그인을 진행합니다.");
signUp(new SignUpRequestDto(
kakaoUser.getEmail(),
Expand All @@ -155,10 +155,12 @@ public SignInResponseDto kakaoAutoSignIn(KakaoProfileDto profile) {
Role.USER,
kakaoUser.getImage()
));
findUser.updateOAuth(KAKAO);
} else {
log.info(profile.getKakao_account().getEmail()+": 기존 회원이므로 자동 로그인을 진행합니다.");
}

User findUser = userRepository.findByEmail(kakaoUser.getEmail()).orElseThrow(()->new UserNotFoundException("카카오 회원가입 도중 문제가 발생했습니다."));
findUser.updateOAuth(KAKAO);
return signIn(kakaoUser.getEmail(), kakaoUser.getPassword());
}

Expand Down
Loading