POST /api/auth/logout
Logs out a user by invalidating their refresh token. This endpoint removes the refresh token from the database, preventing it from being used to obtain new access tokens.Request body
Refresh token to invalidate. This parameter is optional—the endpoint will succeed even if no token is provided
Response
Always returns true
Confirmation message
Status codes
200- Logout successful500- Internal server error
This endpoint is idempotent and always returns success. You can call it multiple times with the same token or without a token.
Examples
Success response (200)
Best practices
For a complete logout implementation:- Client-side cleanup: Delete both access and refresh tokens from local storage, cookies, or wherever they’re stored
- Server-side invalidation: Call this endpoint to remove the refresh token from the database
- Redirect: Navigate the user to the login page or home page
- Clear state: Reset any user-specific application state or cached data
Security considerations
- Access tokens remain valid: Since JWTs are stateless, the access token will remain valid until it expires (default: 1 hour). Design your application with short-lived access tokens for better security.
- Multiple sessions: If a user has multiple sessions (different devices), each has a unique refresh token. This endpoint only invalidates the specific refresh token provided.
- Token deletion: The endpoint deletes all refresh tokens matching the provided token string, ensuring complete invalidation even if duplicates exist.