This API supports multi-session authentication, allowing users to be logged in from multiple devices simultaneously. The session management endpoints provide users with visibility and control over their active sessions.
Session Configuration:
The system automatically manages sessions through:
/api/auth/sessions
Get all active sessions for the current user (requires authentication)
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr...
Response (200 OK):
{ "sessions": [ { "id": 1, "deviceIdentifier": "Chrome-MacOS-12345", "ipAddress": "192.168.1.100", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36", "createdAt": "2023-12-01T10:30:00Z", "lastAccessedAt": "2023-12-01T14:45:00Z", "isCurrent": true }, { "id": 2, "deviceIdentifier": "Safari-iPhone-67890", "ipAddress": "192.168.1.101", "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15", "createdAt": "2023-11-30T08:15:00Z", "lastAccessedAt": "2023-11-30T18:20:00Z", "isCurrent": false } ], "maxSessions": 5, "multipleSessionsEnabled": true }
Notes:
isCurrent
field indicates which session corresponds to the current requestmaxSessions
is returned as a number, not a stringdeviceIdentifier
, ipAddress
, and userAgent
may be null if not captured during session creation/api/auth/sessions/revoke-others
Revoke all other sessions except the current one. This is useful when a user suspects their account has been compromised and wants to log out all other devices while keeping their current session active.
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr...
Response (200 OK):
{ "message": "Successfully revoked 3 other sessions", "revokedCount": 3 }
Error Responses:
{ "message": "No authentication token provided" } { "message": "Invalid session" }
Notes:
/api/auth/sessions/:sessionId
Revoke a specific session by ID. Users can only revoke their own sessions.
Headers:
Authorization: Bearer ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr...
URL Parameters:
sessionId: The ID of the session to revoke (integer)
Response (200 OK):
{ "message": "Session revoked successfully" }
Error Responses:
{ "message": "Session not found" } { "message": "Failed to revoke session" }
Notes: