diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java index 19f6b325..9eaa75a5 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/entity/User.java @@ -31,7 +31,7 @@ public class User extends BaseTimeEntity implements UserDetails { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(length = 60, nullable = false, unique = true) + @Column(length = 60, nullable = false) private String username; @Column(length = 60) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java index 5f62009a..f02937fb 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/UserRepository.java @@ -8,4 +8,6 @@ public interface UserRepository extends JpaRepository { User findByUsername(String username); User findByNickname(String nickname); + + User findByUsernameAndDeletedAtIsNull(String username); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java index c93721ed..c3d085ad 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/AuthService.java @@ -40,7 +40,7 @@ public class AuthService { public JwtTokenDto signUp(SignUpDto signUpDto) { User user = User.builder() .username(signUpDto.getUsername()) - .password(passwordEncoder.encode(signUpDto.getPassword())) + .password(signUpDto.getPassword()) .nickname(signUpDto.getNickname()) .role(Role.USER) .build(); @@ -132,7 +132,7 @@ private JwtTokenDto generateJwtTokenDto(User user) { */ @Transactional public void signOut(String username, SignOutDto signOutDto) { - User user = userRepository.findByUsername(username); + User user = userRepository.findByUsernameAndDeletedAtIsNull(username); if (user == null || user.getDeletedAt() != null) { throw new BusinessException("존재하지 않는 사용자입니다.", StatusEnum.UNAUTHORIZED); } diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java index a28cb38f..896eb2e3 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java @@ -62,7 +62,7 @@ public User create(User user) { } public boolean isDuplicateUsername(String username) { - return userRepository.findByUsername(username) != null; + return userRepository.findByUsernameAndDeletedAtIsNull(username) != null; } public boolean isValidatePassword(String password) { @@ -74,7 +74,7 @@ public boolean isValidatePassword(String password) { } public User read(String username) { - User user = userRepository.findByUsername(username); + User user = userRepository.findByUsernameAndDeletedAtIsNull(username); if (user == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -104,7 +104,7 @@ public List list() { } public UserUpdateResponseDto update(String username, Long userId, UserUpdateRequestDto userUpdateRequestDto) { - User user = userRepository.findByUsername(username); + User user = userRepository.findByUsernameAndDeletedAtIsNull(username); if (user == null) { throw new BusinessException("존재하지 않는 회원입니다.", StatusEnum.NOT_FOUND); } @@ -166,7 +166,11 @@ public OAuth deleteOAuthInfo(User user, OAuthPlatform oAuthPlatform) { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - return userRepository.findByUsername(username).getDeletedAt() == null ? userRepository.findByUsername(username) : null; + User user = userRepository.findByUsernameAndDeletedAtIsNull(username); + if (user == null) { + throw new UsernameNotFoundException("존재하지 않는 회원입니다."); + } + return user; } public List deleteOAuthInfo(User user) {