Skip to content

Commit

Permalink
[FEAT] 로그아웃 HTTP method 변경 (#150)
Browse files Browse the repository at this point in the history
* feat: 로그아웃 비즈니스 예외 구현

* refactor: 로그아웃 method 변경

GET에서 POST로 변경

* config: 프론트 URL 변경
  • Loading branch information
Profile-exe authored Sep 12, 2024
1 parent 3012a1f commit 423ea63
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import econo.buddybridge.auth.OAuthProvider;
import econo.buddybridge.auth.dto.kakao.KakaoLoginParams;
import econo.buddybridge.auth.exception.AlreadyLogoutException;
import econo.buddybridge.auth.service.OAuthLoginService;
import econo.buddybridge.common.annotation.AllowAnonymous;
import econo.buddybridge.member.dto.MemberResDto;
Expand Down Expand Up @@ -39,15 +40,15 @@ public class AuthController {

@Operation(summary = "로그아웃", description = "세션을 제거합니다.")
@AllowAnonymous
@GetMapping("/logout")
@PostMapping("/logout")
public ApiResponse<CustomBody<String>> logout(HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
oAuthLoginService.logout(OAuthProvider.KAKAO);
return ApiResponseGenerator.success("로그아웃 성공", HttpStatus.OK);
}
return ApiResponseGenerator.success("이미 로그아웃 상태입니다.", HttpStatus.OK);
throw AlreadyLogoutException.EXCEPTION;
}

@Operation(summary = "카카오 소셜 로그인 (코드로 로그인)", description = "Redirect URL이 백엔드 주소로 설정될 때 사용합니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package econo.buddybridge.auth.exception;

import econo.buddybridge.common.exception.BusinessException;

public class AlreadyLogoutException extends BusinessException {

public static BusinessException EXCEPTION = new AlreadyLogoutException();

public AlreadyLogoutException() {
super(AuthErrorCode.ALREADY_LOGOUT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum AuthErrorCode implements ErrorCode {
SESSION_ALREADY_EXISTS("A001", HttpStatus.BAD_REQUEST, "이미 세션이 존재합니다. 삭제 응답 후 다시 시도해주세요."),
FEIGN_REDIRECT("A002", HttpStatus.OK, "Feign Client Logout Redirect"),
FEIGN_KAKAO_EXCEPTION("A003", HttpStatus.BAD_REQUEST, "카카오 API 호출 오류가 발생했습니다."),
ALREADY_LOGOUT("A004", HttpStatus.BAD_REQUEST, "이미 로그아웃 상태입니다."),
;

private final String code;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/econo/buddybridge/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public void addCorsMappings(CorsRegistry registry) { // CORS 설정
"http://localhost:3000", "https://localhost:3000",
"http://localhost:8080", "https://localhost:8080",
"http://localhost:8081", "https://localhost:8081",
"https://buddybridge-git-master-simminbos-projects.vercel.app/",
"https://buddybridge-simminbos-projects.vercel.app/"
"https://buddy-bridge.vercel.app/"
)
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
Expand Down

0 comments on commit 423ea63

Please sign in to comment.