Endpoint
POST
/auth/logout
Required - Must include valid access token in cookie
Request
Headers
application/json
Must include
accessToken cookie for authenticationBody Parameters
Optional. The refresh token to revoke (128-character hexadecimal string)If not provided, no specific token is revoked (only cookies are cleared)
Optional. If
true, revokes ALL refresh tokens for the user (logout from all devices)Default: falseExample Request
Logout from Current Device
cURL
Logout from All Devices
cURL
JavaScript
JavaScript
Python
Response
Success Response (200)
Always
true for successful requestsSuccess message indicating logout scope:
- “Logout realizado com sucesso” (single device)
- “Logout realizado em todos os dispositivos” (all devices)
Response Cookies
The following cookies are automatically cleared:accessToken: Cleared (set to empty with past expiration)refreshToken: Cleared (set to empty with past expiration)
Example Success Response (Single Device)
Example Success Response (All Devices)
Error Responses
Unauthorized - Missing Token (401)
Unauthorized - Invalid Token (401)
Validation Error (400)
Logout Behavior
The logout endpoint has three modes of operation:1. Logout with Refresh Token
When you provide arefreshToken:
- The specific refresh token is revoked in the database
- Auth cookies are cleared from the browser
- Other devices/sessions remain active
2. Logout from All Devices
When you setallDevices: true:
- ALL refresh tokens for the user are revoked
- The user is logged out from all browsers and devices
- Auth cookies are cleared from the current browser
- Useful for security purposes (e.g., password change, suspicious activity)
3. Logout without Parameters
When you don’t provide any parameters:- Auth cookies are cleared from the browser
- No tokens are revoked in the database
- This is a “soft” logout (user can still use other sessions)
Security Features
- Requires Authentication: Must have a valid access token
- Activity Logging: Logout events are logged for security auditing
- Cookie Cleanup: Automatically clears HttpOnly cookies
- Token Revocation: Marks tokens as revoked in the database
- Multi-Device Support: Can end all sessions across devices
Use Cases
Normal Logout
User clicks “Logout” button in your app:Security Logout (All Devices)
User changes password or detects suspicious activity:Quick Logout (Cookie Clear Only)
User wants to clear browser session without affecting other devices:Notes
- Authentication Required: This endpoint requires a valid access token
- Cookie Handling: Cookies are automatically cleared regardless of parameters
- Token Format: Refresh tokens must be 128-character hexadecimal strings
- Activity Logging: Logout events are logged with timestamp and action type
- No Rate Limiting: The basic logout endpoint is not rate-limited (unlike session management)