diff --git a/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java b/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java index d6e8df6..7edd923 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java +++ b/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java @@ -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 = "abcde@gmail.com") + private String email; @Schema(description = "비밀번호", example = "password") private String password; } diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java index 6da8c1b..504e718 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java @@ -79,23 +79,19 @@ public JwtDto signup(SignupRequest request) { @Override public JwtDto login(LoginRequest request) { // bring user's phone number - Optional userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber()); +// Optional userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber()); - if (userIdentityJpaEntity.isEmpty()) - throw new CustomException(ErrorCode.NotFound, "전화번호를 확인해주세요", HttpStatus.NOT_FOUND); + Optional user = userRepository.findByEmailWithoutWithdraw(request.getEmail()); - // bring user's password - String userId = userIdentityJpaEntity.get().getUserId(); - Optional 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