File tree Expand file tree Collapse file tree
src/main/java/com/example/FixLog Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import com .example .FixLog .dto .Response ;
44import com .example .FixLog .dto .member .LoginRequestDto ;
55import com .example .FixLog .dto .member .LoginResponseDto ;
6+ import com .example .FixLog .exception .ErrorCode ;
67import com .example .FixLog .service .AuthService ;
8+ import jakarta .servlet .http .HttpServletRequest ;
79import lombok .RequiredArgsConstructor ;
810import org .springframework .http .ResponseEntity ;
911import org .springframework .web .bind .annotation .*;
@@ -20,4 +22,18 @@ public ResponseEntity<Response<LoginResponseDto>> login(@RequestBody LoginReques
2022 LoginResponseDto result = authService .login (requestDto );
2123 return ResponseEntity .ok (Response .success ("로그인 성공" , result ));
2224 }
25+
26+ @ PostMapping ("/logout" )
27+ public ResponseEntity <Response <String >> logout (HttpServletRequest request ) {
28+ String token = request .getHeader ("Authorization" );
29+
30+ if (token != null && token .startsWith ("Bearer " )) {
31+ return ResponseEntity .ok (Response .success ("로그아웃 완료. 클라이언트에서 토큰을 삭제하세요." , null ));
32+ } else {
33+ return ResponseEntity
34+ .badRequest ()
35+ .body (Response .fail (ErrorCode .UNAUTHORIZED .getMessage ()));
36+ }
37+ }
38+
2339}
Original file line number Diff line number Diff line change 99public enum ErrorCode {
1010 USER_NICKNAME_NOT_FOUND (HttpStatus .NOT_FOUND ,"존재하지 않는 사용자 아이디입니다." ),
1111 USER_EMAIL_NOT_FOUND (HttpStatus .NOT_FOUND , "회원 이메일을 찾을 수 없습니다." ),
12+ USER_DELETED (HttpStatus .FORBIDDEN , "탈퇴한 회원입니다." ),
1213 EMAIL_DUPLICATED (HttpStatus .CONFLICT , "중복된 이메일입니다" ),
1314 NICKNAME_DUPLICATED (HttpStatus .CONFLICT , "중복된 닉네임입니다" ),
1415 ALREADY_FOLLOWING (HttpStatus .CONFLICT , "이미 팔로우 중입니다" ),
@@ -29,7 +30,11 @@ public enum ErrorCode {
2930 UNAUTHORIZED (HttpStatus .UNAUTHORIZED , "권한이 없습니다." ),
3031 INVALID_REQUEST (HttpStatus .BAD_REQUEST , "요청 데이터가 유효하지 않습니다." ),
3132 S3_UPLOAD_FAILED (HttpStatus .BAD_REQUEST , "S3 파일 업로드에 실패했습니다." ),
33+ <<<<<<< HEAD
3234 IMAGE_UPLOAD_FAILED (HttpStatus .NOT_FOUND , "이미지 파일이 업로드되지 않았습니다." );
35+ =======
36+ LOGOUT_SUCCESS (HttpStatus .OK , "로그아웃이 정상적으로 처리되었습니다 .");
37+ >>>>>>> 7375 c5c (fix (auth ): 로그인 시 탈퇴 사용자 처리 및 오류 코드 추가 )
3338
3439 private final HttpStatus status ;
3540 private final String message ;
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ public LoginResponseDto login(LoginRequestDto requestDto) {
2626 Member member = memberRepository .findByEmail (requestDto .getEmail ())
2727 .orElseThrow (() -> new CustomException (ErrorCode .USER_NICKNAME_NOT_FOUND ));
2828
29+ if (member .getIsDeleted ()) {
30+ throw new CustomException (ErrorCode .USER_DELETED );
31+ }
32+
2933 if (!passwordEncoder .matches (requestDto .getPassword (), member .getPassword ())) {
3034 throw new CustomException (ErrorCode .INVALID_PASSWORD );
3135 }
You can’t perform that action at this time.
0 commit comments