Context
I'm implementing a logout feature in my Spring Boot application that clears an authentication cookie and returns a success message:
@RestController
@RequestMapping("/auth")
public class AuthController {
// ... constructor and other endpoints
@PostMapping("/private/logout")
public LogoutResponse logout(HttpServletResponse response) {
log.info("[AUTH] User logging out.");
jwtUtils.clearTokenCookie(response);
return new LogoutResponse("Logout Successful!");
}
}
This works fine in Postman—I receive the expected JSON response:
{
"message": "Logout Successful!"
}
Issue
However, my IDE (IntelliJ IDEA 2024.1.2 (Community Edition)) is showing a warning:
"Return value of the method is never used"
What I've Considered
- Could this be due to Spring Security filters interfering with the response?
- Since I'm modifying cookies via HttpServletResponse, could this affect Spring Boot’s handling of the response?
- I tried using ResponseEntity, but the warning persists:
@PostMapping("/private/logout")
public ResponseEntity<LogoutResponse> logout(HttpServletResponse response) {
jwtUtils.clearTokenCookie(response);
return ResponseEntity.ok(new LogoutResponse("Logout Successful!"));
}
I suspect I can just ignore this warning, but I’m curious:
- Why does Spring Boot think the return value is unused?
- Does modifying HttpServletResponse interfere with Spring's response handling?
- Is there a best practice for structuring logout endpoints that modify cookies?