99import jakarta .servlet .http .HttpServletResponse ;
1010import lombok .RequiredArgsConstructor ;
1111import lombok .extern .slf4j .Slf4j ;
12+ import org .springframework .http .HttpHeaders ;
1213import org .springframework .security .core .annotation .AuthenticationPrincipal ;
1314import org .springframework .web .bind .annotation .*;
1415
1516import java .net .URI ;
1617import java .time .LocalDateTime ;
1718
1819import static com .wootech .transtalk .config .util .CookieUtil .addRefreshTokenCookie ;
20+ import static com .wootech .transtalk .config .util .CookieUtil .deleteRefreshTokenCookie ;
21+ import static com .wootech .transtalk .exception .ErrorMessages .ACCESS_TOKEN_DOES_NOT_EXISTS_ERROR ;
1922
2023@ Slf4j
2124@ RequiredArgsConstructor
@@ -69,12 +72,25 @@ public ApiResponse<Object> logOut() {
6972
7073 // 회원탈퇴
7174 @ DeleteMapping ("/withdraw" )
72- public ApiResponse <Object > withdrawUser (@ AuthenticationPrincipal AuthUser authUser ) {
73- userService .withdrawUser (authUser );
74- return ApiResponse .builder ()
75- .success (true )
76- .message ("회원탈퇴에 성공했습니다." )
77- .timestamp (LocalDateTime .now ())
78- .build ();
75+ public ApiResponse <Object > withdrawUser (
76+ @ RequestHeader (HttpHeaders .AUTHORIZATION ) String authorizationHeader ,
77+ @ AuthenticationPrincipal AuthUser authUser ,
78+ HttpServletResponse response
79+ ) {
80+ String accessToken = null ;
81+ if (authorizationHeader != null && authorizationHeader .startsWith ("Bearer " )) {
82+ accessToken = authorizationHeader .substring ("Bearer " .length ()).trim ();
83+ }
84+ if (accessToken != null ) {
85+ authService .withdrawUser (authUser , accessToken );
86+ deleteRefreshTokenCookie (response );
87+ return ApiResponse .builder ()
88+ .success (true )
89+ .message ("회원탈퇴에 성공했습니다." )
90+ .timestamp (LocalDateTime .now ())
91+ .build ();
92+ } else {
93+ throw new IllegalArgumentException (ACCESS_TOKEN_DOES_NOT_EXISTS_ERROR );
94+ }
7995 }
8096}
0 commit comments