POST /api/v1/auth/logout
Revokes a refresh token to end a user session. After logout, the refresh token can no longer be used to obtain new access tokens.Request Body
The JWT refresh token to revokeAfter revocation, this token cannot be used for token refresh.
Response
Indicates if the request was successful
Error Responses
This endpoint is designed to be fault-tolerant and will always return a 200 success response, even if:- The refresh token is invalid
- The refresh token has already been revoked
- The refresh token has expired
- The refresh token is malformed
Session Management
The logout endpoint is part of a comprehensive session management system:Single Session Logout
The/api/v1/auth/logout endpoint revokes a single refresh token, ending one session.
Multi-Device Support
The system tracks multiple active sessions per user:- Each device can have its own active session
- Sessions are identified by
deviceIdand tracked with:- Device name (e.g., “Chrome · Windows”)
- IP address
- User agent
- Last used timestamp
- Creation timestamp
Related Endpoints
Logout All Sessions
Revoke all active sessions for the authenticated userEndpoint:
POST /api/v1/auth/logout/allGet User Sessions
List all active sessions for a user (requires authentication)Endpoint:
GET /api/v1/auth/sessions/user/:userIdRevoke Specific Session
Revoke a specific session by ID (requires authentication)Endpoint:
DELETE /api/v1/auth/sessions/:sessionIdToken Revocation Details
When a token is successfully revoked:- The token is marked with
revoked: truein the database - A
revokedAttimestamp is recorded - The
revokedReasonis set to"logout" - The token can no longer be used for refresh operations
Security Considerations
- Access tokens remain valid - This endpoint only revokes the refresh token. The current access token will remain valid until it expires (typically a short duration). For immediate session termination across all tokens, consider implementing access token blacklisting or using short-lived access tokens.
- Silent failure - The endpoint doesn’t reveal whether a token was valid or not, preventing attackers from testing token validity.
-
Client-side cleanup - After logout:
- Clear both access and refresh tokens from storage
- Redirect to the login page
- Clear any cached user data