-
Notifications
You must be signed in to change notification settings - Fork 1
[배포]: 카카오 중복 판단 로직 추가 및 로그 제거 #351
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
Changes from all commits
9398774
143b130
106b086
41b5f85
02cd07f
9cd61d0
46c68a7
a30848f
4192592
3b3bc43
3b3db36
57b1aa8
88d8a26
c010aba
fd85069
d1085cb
c4dc8dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,28 @@ public class SignUpAccountStepProcessor implements StepProcessor<UserJpaEntity, | |
| @Transactional | ||
| @Override | ||
| public UserJpaEntity process(UserJpaEntity user) { | ||
| if (userRepository.existsByPhoneNumber(user.getOriginPhoneNumber())) { | ||
| throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS); | ||
| } else if (userRepository.existsByLoginId(user.getLoginId())) { | ||
|
|
||
| validateForNewSignUp(user); | ||
|
|
||
| return userRepository.save(user); | ||
| } | ||
|
|
||
| private void validateForNewSignUp(UserJpaEntity user) { | ||
|
|
||
| userRepository.findByPhoneNumber(user.getOriginPhoneNumber()) | ||
| .ifPresent(existingUser -> { | ||
| if (existingUser.isPendingUser()) { | ||
| switch (existingUser.getProvider()) { | ||
| case MOSU: | ||
| throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS); | ||
| case KAKAO: | ||
| throw new CustomRuntimeException(ErrorCode.KAKAO_DUPLICATED); | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
+31
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 회원가입 시 사용자를 검증하는 로직에 잠재적인 문제가 있습니다. 현재 코드는 전화번호로 사용자를 조회한 후, 해당 사용자가 기존 사용자가 userRepository.findByPhoneNumber(user.getOriginPhoneNumber())
.ifPresent(existingUser -> {
if (existingUser.isPendingUser()) {
switch (existingUser.getProvider()) {
case KAKAO:
throw new CustomRuntimeException(ErrorCode.KAKAO_DUPLICATED);
case MOSU:
default:
throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS);
}
}
// 사용자가 존재하지만 PENDING 상태가 아닌 경우에도 중복으로 처리합니다.
throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS);
}); |
||
|
|
||
| if (userRepository.existsByLoginId(user.getLoginId())) { | ||
| throw new CustomRuntimeException(ErrorCode.USER_ALREADY_EXISTS); | ||
| } | ||
| log.info("Processing user sign-up: {}", user); | ||
| return userRepository.save(user); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,20 +17,23 @@ public class OAuthUserPersistenceProcessor implements StepProcessor<OAuthUserInf | |
|
|
||
| private final UserJpaRepository userRepository; | ||
|
|
||
| /** | ||
| * this method is processing OAuthUserInfo to UserJpaEntity that is Get or Create. | ||
| * | ||
| * @param info | ||
| * @return | ||
| */ | ||
| @Override | ||
| @Transactional | ||
| public UserJpaEntity process(final OAuthUserInfo info) { | ||
| return userRepository.findByPhoneNumber( | ||
| PhoneNumberUtil.formatPhoneNumber(info.phoneNumber())) | ||
| .map(existingUser -> { | ||
| if (existingUser.isMosuUser()) { | ||
| throw new OAuthException("DUPLICATE"); | ||
| switch (existingUser.getProvider()) { | ||
| case MOSU: | ||
| if (existingUser.isPendingUser()) { | ||
| throw new OAuthException("DUPLICATE"); | ||
| } | ||
| break; | ||
| case KAKAO: | ||
| if (existingUser.isPendingUser()) { | ||
| throw new OAuthException("KAKAO_DUPLICATE"); | ||
| } | ||
| break; | ||
| } | ||
|
Comment on lines
+26
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
향후 확장성을 고려하여 switch (existingUser.getProvider()) {
case MOSU:
if (existingUser.isPendingUser()) {
throw new OAuthException("DUPLICATE");
}
break;
case KAKAO:
if (existingUser.isPendingUser()) {
throw new OAuthException("KAKAO_DUPLICATE");
}
break;
default:
// 새로운 Provider에 대한 처리를 명시적으로 하거나, 아무것도 하지 않음을 주석으로 남기는 것이 좋습니다.
break;
} |
||
| existingUser.updateOAuthUser( | ||
| info.gender(), | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| package life.mosu.mosuserver.domain.auth.signup; | ||
| package life.mosu.mosuserver.domain.auth.token; | ||
|
|
||
| public record Token( | ||
| String certNum, | ||
| Long expiration | ||
| ) { | ||
|
|
||
| public static Token of(String certNum, Long expiration) { | ||
| return new Token(certNum, expiration); | ||
| } | ||
|
|
||
| public static Token from(SignUpTokenRedisEntity signUpTokenRedisEntity) { | ||
| public static Token from(TokenRedisEntity tokenRedisEntity) { | ||
| return new Token( | ||
| signUpTokenRedisEntity.getCertNum(), | ||
| signUpTokenRedisEntity.getExpiration() | ||
| tokenRedisEntity.getCertNum(), | ||
| tokenRedisEntity.getExpiration() | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package life.mosu.mosuserver.domain.auth.token; | ||
|
|
||
| import org.springframework.data.keyvalue.repository.KeyValueRepository; | ||
|
|
||
| public interface TokenKeyValueRepository extends | ||
| KeyValueRepository<TokenRedisEntity, String> { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package life.mosu.mosuserver.global.exception; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public enum CriticalLevel { | ||
| LOW("낮음"), | ||
| MEDIUM("중간"), | ||
| HIGH("높음"), | ||
| CRITICAL("심각함"); | ||
|
|
||
| private final String description; | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public boolean isEmergency() { | ||
| return this == HIGH || this == CRITICAL; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.description; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validateForNewSignUp메서드의 중복 사용자 검증 로직이 모든 케이스를 처리하지 못하고 있습니다. 현재 코드는PENDING상태의 사용자에 대해서만 중복을 검사하고, 이미 가입이 완료된 사용자에 대해서는 아무런 처리를 하지 않아DataIntegrityViolationException이 발생할 수 있습니다.또한,
switch문에default케이스가 없어 새로운AuthProvider가 추가될 경우를 대비하지 못하고 있습니다.아래와 같이 수정하여 모든 중복 케이스를 처리하고 코드를 단순화하는 것을 제안합니다. 이 로직은 카카오 중복 가입 시도에 대해 특정 에러를 발생시키고, 그 외 모든 중복 상황에서는 일반적인 "사용자 존재" 에러를 발생시킵니다.