Skip to content

Commit

Permalink
✨ 기능 추가 : 직원 로그아웃 Controller 기능 추가
Browse files Browse the repository at this point in the history
✨ 기능 추가 : 직원 로그아웃 Controller 기능 추가
  • Loading branch information
sksmsdlskgus authored Nov 26, 2024
2 parents dfa4cfb + 240926a commit e48b166
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import intbyte4.learnsmate.admin.mapper.AdminMapper;
import intbyte4.learnsmate.admin.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -44,6 +46,7 @@ public ResponseEntity<ResponseEditAdminVO> updateAdmin(@PathVariable Long adminC

// @AuthenticationPrincipal을 활용 -> CustomUserDetails에서 사용자 정보를 추출
// 인증 성공 시 사용자 이름과 권한을 상태에 저장 -> Pinia 로 이름과 권한 정보 넘어감 (loginState.js 롹인 바람)
@Operation(summary = "직원 정보 조회")
@GetMapping("/status")
public ResponseEntity<Map<String, Object>> checkAuthStatus(@AuthenticationPrincipal CustomUserDetails userDetails) {
log.info("GET /admin/status 요청 도착");
Expand All @@ -57,4 +60,21 @@ public ResponseEntity<Map<String, Object>> checkAuthStatus(@AuthenticationPrinci

return ResponseEntity.ok(response);
}

@Operation(summary = "직원 로그아웃")
@PostMapping("/logout")
public ResponseEntity<?> logout(HttpServletResponse response) {
log.info("POST /admin/logout 요청 도착");
// 쿠키 삭제 명령
Cookie cookie = new Cookie("token", null);
cookie.setPath("/");
cookie.setHttpOnly(true);
cookie.setMaxAge(0); // 쿠키 만료 처리
response.addCookie(cookie);

// 필요 시 블랙리스트로 JWT 관리
log.info("로그아웃 성공");
return ResponseEntity.ok().body("로그아웃 성공");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ protected SecurityFilterChain configure(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher("/users/verify-code")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/send-sms")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/admin/**","GET")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/admin/**","POST")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/**", "POST")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/**", "OPTIONS")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/nickname/check", "GET")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/oauth2", "GET")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/**", "GET")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/**", "PATCH")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/users/mypage/edit/password", "PATCH")).permitAll()
Expand Down

0 comments on commit e48b166

Please sign in to comment.