POST /api/logout
Logs out the authenticated user by invalidating their refresh token and clearing authentication cookies.Headers
Bearer token for authenticationFormat:
Bearer <access_token>Authentication
This endpoint requires a valid JWT access token. The user is identified from the token payload.Response
Success message
Indicates successful logout
Cookies Cleared
The refresh token cookie is cleared from the client
Status Codes
200- Logout successful401- Unauthorized (invalid or missing access token)500- Internal server error
Example Request
Example Response
Error Responses
Process Flow
- Validates JWT access token from Authorization header
- Retrieves authenticated user from token payload
- Clears the user’s refresh token in the database
- Clears the
refreshTokencookie from the client - Returns success response
Notes
- After logout, both the access token and refresh token become invalid
- The client should discard any stored tokens after receiving a successful logout response
- The refresh token is set to an empty string in the database
- The operation uses
validateBeforeSave: falsefor performance