Skip to content

Commit

Permalink
Merge pull request #16 from With-Mate/feat/auth-2/sh
Browse files Browse the repository at this point in the history
fix(Auth) : 로그인 실패 시 상태코드 처리 수정
  • Loading branch information
seohyun-lee authored Feb 16, 2024
2 parents 8f4aabc + 63e2cdd commit baa3ad1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
Expand Down Expand Up @@ -39,11 +40,10 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
AuthDetails authDetails = (AuthDetails) authentication.getPrincipal();
return authentication;

} catch (Exception e) {
} catch (IOException e) {
// Member 매핑 불가: 로그인 불가
e.printStackTrace();
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ResponseEntity<?> userLogin(@RequestBody LoginReqDto loginReqDto) {
String message = authService.memberLogin(loginReqDto);
if (message.isBlank())
return ResponseEntity.badRequest().body("로그인에 실패했습니다. 이메일 또는 비밀번호가 일치하는지 확인해주세요.");
return ResponseEntity.status(HttpStatus.CREATED.value()).body("로그인 성공. 토큰이 발급되었습니다.");
return ResponseEntity.ok().body("로그인 성공. 토큰이 발급되었습니다.");
}

// 로그아웃
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -79,12 +80,11 @@ public String memberLogin(LoginReqDto loginRequestDto) { // 기본 로그인
log.info("JWT 토큰 반환");
return jwtTokenProvider.generateJwtToken(authenticatedId, authenticatedUserName);
}
return null;
} catch(AuthenticationException e){
// 인증 실패 시 예외 처리
log.error("사용자 인증 실패: {}", e.getMessage());
// 인증 실패 시
return null;
}
return null;
}

public String memberLogout(HttpServletRequest request) {
Expand Down

0 comments on commit baa3ad1

Please sign in to comment.