Skip to content

Commit

Permalink
[fix] 로그인 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ksj000625 committed Dec 22, 2024
1 parent 6f67a20 commit 0c4fd39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

@Data
public class LoginRequest {
@Schema(description = "전화번호", example = "010-0000-0001")
private String phoneNumber;
// @Schema(description = "전화번호", example = "010-0000-0001")
// private String phoneNumber;
@Schema(description = "이메일", example = "[email protected]")
private String email;
@Schema(description = "비밀번호", example = "password")
private String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,19 @@ public JwtDto signup(SignupRequest request) {
@Override
public JwtDto login(LoginRequest request) {
// bring user's phone number
Optional<UserIdentityJpaEntity> userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber());
// Optional<UserIdentityJpaEntity> userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber());

if (userIdentityJpaEntity.isEmpty())
throw new CustomException(ErrorCode.NotFound, "전화번호를 확인해주세요", HttpStatus.NOT_FOUND);
Optional<UserJpaEntity> user = userRepository.findByEmailWithoutWithdraw(request.getEmail());

// bring user's password
String userId = userIdentityJpaEntity.get().getUserId();
Optional<UserJpaEntity> userJpaEntity = userRepository.findById(userId);
if (userJpaEntity.isEmpty())
throw new CustomException(ErrorCode.NotFound, "해당 회원이 존재하지 않습니다.", HttpStatus.NOT_FOUND);
// if user already exists
if (user.isEmpty())
throw new CustomException(ErrorCode.Conflict, "해당 회원이 존재하지 않습니다.", HttpStatus.CONFLICT);

String encryptedPassword = userJpaEntity.get().getPassword();
String encryptedPassword = user.get().getPassword();
if (!checkPassword(request.getPassword(), encryptedPassword))
throw new CustomException(ErrorCode.Unauthorized, "비밀번호를 확인해 주세요.", HttpStatus.UNAUTHORIZED);


return jwtUtil.generateJwtDto(userId, userJpaEntity.get().getRole());

return jwtUtil.generateJwtDto(user.get().getUserId(), user.get().getRole());
}

@Override
Expand Down

0 comments on commit 0c4fd39

Please sign in to comment.