Skip to content

Commit

Permalink
♻️ 카카오 로그인 닉네임 반복 랜덤생성 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdals4716 committed Oct 31, 2024
1 parent 0572250 commit 42285b4
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/main/java/com/example/moyeothon/Service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,8 @@ public JWTDTO loginWithOAuth2(String code) {
@SuppressWarnings("unchecked")
Map<String, Object> kakaoAccount = (Map<String, Object>) userInfo.get("kakao_account");

String name = null;
String nickname = null;
if (properties != null) {
name = (String) properties.get("nickname");
}
if (name == null) {
name = "카카오사용자";
}

if (nickname == null) {
nickname = randomNickname();
}

String email = null;
if (kakaoAccount != null) {
email = (String) kakaoAccount.get("email");
}
String name = (properties != null) ? (String) properties.get("nickname") : "카카오사용자";
String email = (kakaoAccount != null) ? (String) kakaoAccount.get("email") : null;
if (email == null) {
throw new RuntimeException("사용자 이메일을 가져올 수 없습니다.");
}
Expand All @@ -234,6 +219,8 @@ public JWTDTO loginWithOAuth2(String code) {

boolean isNewUser = false;
if (userEntity == null) {
// 새 유저일 때만 랜덤 닉네임 생성
String nickname = randomNickname();
userEntity = UserEntity.builder()
.uid(uid)
.nickname(nickname)
Expand All @@ -245,8 +232,8 @@ public JWTDTO loginWithOAuth2(String code) {
userRepository.save(userEntity);
isNewUser = true;
} else {
// 기존 유저일 경우, 닉네임 변경 없이 다른 정보만 업데이트
userEntity.setName(name);
userEntity.setNickname(nickname);
userEntity.setEmail(email);
userRepository.save(userEntity);
}
Expand Down

0 comments on commit 42285b4

Please sign in to comment.