From 0571d71d094316861d571cc16e308fc5c0e21660 Mon Sep 17 00:00:00 2001 From: sungchaewon Date: Sun, 22 Jun 2025 18:17:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix(auth):=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=9C=20=ED=83=88=ED=87=B4=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20=EC=98=A4=EB=A5=98=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FixLog/controller/AuthController.java | 16 ++++++++++++++++ .../com/example/FixLog/exception/ErrorCode.java | 5 +++++ .../com/example/FixLog/service/AuthService.java | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/src/main/java/com/example/FixLog/controller/AuthController.java b/src/main/java/com/example/FixLog/controller/AuthController.java index 2aa535c..4acd281 100644 --- a/src/main/java/com/example/FixLog/controller/AuthController.java +++ b/src/main/java/com/example/FixLog/controller/AuthController.java @@ -3,7 +3,9 @@ import com.example.FixLog.dto.Response; import com.example.FixLog.dto.member.LoginRequestDto; import com.example.FixLog.dto.member.LoginResponseDto; +import com.example.FixLog.exception.ErrorCode; import com.example.FixLog.service.AuthService; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -20,4 +22,18 @@ public ResponseEntity> login(@RequestBody LoginReques LoginResponseDto result = authService.login(requestDto); return ResponseEntity.ok(Response.success("로그인 성공", result)); } + + @PostMapping("/logout") + public ResponseEntity> logout(HttpServletRequest request) { + String token = request.getHeader("Authorization"); + + if (token != null && token.startsWith("Bearer ")) { + return ResponseEntity.ok(Response.success("로그아웃 완료. 클라이언트에서 토큰을 삭제하세요.", null)); + } else { + return ResponseEntity + .badRequest() + .body(Response.fail(ErrorCode.UNAUTHORIZED.getMessage())); + } + } + } diff --git a/src/main/java/com/example/FixLog/exception/ErrorCode.java b/src/main/java/com/example/FixLog/exception/ErrorCode.java index f60c48d..93549c9 100644 --- a/src/main/java/com/example/FixLog/exception/ErrorCode.java +++ b/src/main/java/com/example/FixLog/exception/ErrorCode.java @@ -9,6 +9,7 @@ public enum ErrorCode { USER_NICKNAME_NOT_FOUND(HttpStatus.NOT_FOUND,"존재하지 않는 사용자 아이디입니다."), USER_EMAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "회원 이메일을 찾을 수 없습니다."), + USER_DELETED(HttpStatus.FORBIDDEN, "탈퇴한 회원입니다."), EMAIL_DUPLICATED(HttpStatus.CONFLICT, "중복된 이메일입니다"), NICKNAME_DUPLICATED(HttpStatus.CONFLICT, "중복된 닉네임입니다"), ALREADY_FOLLOWING(HttpStatus.CONFLICT, "이미 팔로우 중입니다"), @@ -29,7 +30,11 @@ public enum ErrorCode { UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "권한이 없습니다."), INVALID_REQUEST(HttpStatus.BAD_REQUEST, "요청 데이터가 유효하지 않습니다."), S3_UPLOAD_FAILED(HttpStatus.BAD_REQUEST, "S3 파일 업로드에 실패했습니다."), +<<<<<<< HEAD IMAGE_UPLOAD_FAILED(HttpStatus.NOT_FOUND, "이미지 파일이 업로드되지 않았습니다."); +======= + LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃이 정상적으로 처리되었습니다."); +>>>>>>> 7375c5c (fix(auth): 로그인 시 탈퇴 사용자 처리 및 오류 코드 추가) private final HttpStatus status; private final String message; diff --git a/src/main/java/com/example/FixLog/service/AuthService.java b/src/main/java/com/example/FixLog/service/AuthService.java index 31cc96e..c2a0950 100644 --- a/src/main/java/com/example/FixLog/service/AuthService.java +++ b/src/main/java/com/example/FixLog/service/AuthService.java @@ -26,6 +26,10 @@ public LoginResponseDto login(LoginRequestDto requestDto) { Member member = memberRepository.findByEmail(requestDto.getEmail()) .orElseThrow(() -> new CustomException(ErrorCode.USER_NICKNAME_NOT_FOUND)); + if (member.getIsDeleted()) { + throw new CustomException(ErrorCode.USER_DELETED); + } + if (!passwordEncoder.matches(requestDto.getPassword(), member.getPassword())) { throw new CustomException(ErrorCode.INVALID_PASSWORD); } From b677b82aaaeeefc7fcd37c22a931405a9f6c3ea1 Mon Sep 17 00:00:00 2001 From: sungchaewon Date: Sun, 22 Jun 2025 18:23:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix(auth)=20:=20ErrorCode=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/FixLog/exception/ErrorCode.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/example/FixLog/exception/ErrorCode.java b/src/main/java/com/example/FixLog/exception/ErrorCode.java index 93549c9..7e059da 100644 --- a/src/main/java/com/example/FixLog/exception/ErrorCode.java +++ b/src/main/java/com/example/FixLog/exception/ErrorCode.java @@ -30,11 +30,8 @@ public enum ErrorCode { UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "권한이 없습니다."), INVALID_REQUEST(HttpStatus.BAD_REQUEST, "요청 데이터가 유효하지 않습니다."), S3_UPLOAD_FAILED(HttpStatus.BAD_REQUEST, "S3 파일 업로드에 실패했습니다."), -<<<<<<< HEAD - IMAGE_UPLOAD_FAILED(HttpStatus.NOT_FOUND, "이미지 파일이 업로드되지 않았습니다."); -======= + IMAGE_UPLOAD_FAILED(HttpStatus.NOT_FOUND, "이미지 파일이 업로드되지 않았습니다."), LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃이 정상적으로 처리되었습니다."); ->>>>>>> 7375c5c (fix(auth): 로그인 시 탈퇴 사용자 처리 및 오류 코드 추가) private final HttpStatus status; private final String message;