Authentication
Logout
End the user session
POST
Logout
Overview
Closes the session for the authenticated user. Since JWT tokens are stateless, this endpoint primarily serves as a confirmation point. The client must discard the token after receiving the response.The token must be manually removed from client storage (localStorage, cookies, etc.) as JWT tokens cannot be invalidated server-side.
Authentication
Required: Bearer token in Authorization headerRequest Body
No request body required.Response
Indicates if the logout was successful
Confirmation message
Always null for logout responses
Examples
Response Examples
Success (200 OK)
Unauthorized (401)
Error Responses
| Status Code | Description |
|---|---|
| 401 | Missing or invalid token |
| 500 | Internal server error |
Best Practices
Client-Side Token Management
Client-Side Token Management
After a successful logout:
- Remove the token from storage (localStorage, sessionStorage, cookies)
- Clear any cached user data
- Redirect to the login page
- Update application state to reflect logged-out status
Automatic Logout
Automatic Logout
Consider implementing automatic logout in these scenarios:
- Token expiration (24 hours by default)
- Inactivity timeout
- Multiple failed API requests with 401 status
- User account status changes to inactive
Related Endpoints
Login
Authenticate and receive a new token
Get Profile
Retrieve user profile information
Source Code Reference
- Route:
src/routes/auth.routes.js:208 - Controller:
src/controllers/authController.js:logout
Logout
