Skip to content

Commit

Permalink
Merge pull request #159 from survey-mate/fix/158
Browse files Browse the repository at this point in the history
fix: 비밀번호 오류 시 로그인 가능 버그 수정 #158
  • Loading branch information
JinhyeokFang authored Feb 18, 2024
2 parents 2cb6da7 + b41f11b commit 5230f14
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import uk.jinhy.survey_mate_api.auth.application.dto.AuthServiceDTO;
Expand All @@ -28,6 +29,7 @@

@RequiredArgsConstructor
@Service
@Slf4j
public class AuthService {

private final MemberRepository memberRepository;
Expand Down Expand Up @@ -98,8 +100,11 @@ public AuthControllerDTO.JwtResponseDTO login(AuthServiceDTO.LoginDTO dto) {
String id = dto.getId();
String password = dto.getPassword();

if (!memberRepository.existsByMemberId(id)) {
throw new GeneralException(Status.MEMBER_NOT_FOUND);
Member member = memberRepository.findById(id)
.orElseThrow(() -> new GeneralException(Status.MEMBER_NOT_FOUND));

if (!passwordEncoder.matches(password, member.getPassword())) {
throw new GeneralException(Status.PASSWORD_INCORRECT);
}

return AuthControllerDTO.JwtResponseDTO.builder()
Expand Down

0 comments on commit 5230f14

Please sign in to comment.