Skip to main content
POST

Overview

The /logout endpoint invalidates the user’s refresh tokens and ends their session. This is a security best practice that ensures tokens cannot be used after the user has explicitly logged out.
This endpoint requires a valid JWT token in the Authorization header.

Request

Response

Response Fields

Implementation Examples

React Hook for Logout

Complete Auth Context

Logout with Confirmation

Node.js Logout Handler

Global Logout (All Devices)

Use Cases

Standard Logout

  • User clicks logout button
  • Invalidate refresh tokens
  • Clear local storage
  • Redirect to login page

Security Logout

  • Logout from all devices when password is changed
  • Logout when suspicious activity is detected
  • Logout when account is compromised

Session Management

  • Automatic logout on token expiration
  • Logout on browser close (optional)
  • Logout after period of inactivity

Security Considerations

  • Token Invalidation: Always invalidate refresh tokens on the server
  • Local Cleanup: Clear all local tokens and user data
  • Blacklisting: Consider blacklisting access tokens for high-security applications
  • Audit Logging: Log logout events for security monitoring
  • Graceful Degradation: Handle logout failures gracefully

Best Practices

Client-Side

  • Always clear local tokens, even if server call fails
  • Redirect user to appropriate page after logout
  • Show loading state during logout process
  • Handle network errors gracefully

Server-Side

  • Invalidate all refresh tokens for the user
  • Clear any session-related data (reauthentication state, etc.)
  • Log logout events for audit purposes
  • Return success even if token is already invalid

Rate Limiting

  • Endpoint: 20 requests per 5 minutes per user
  • Purpose: Prevent abuse while allowing legitimate logout attempts
  • Headers: Standard rate limiting headers included in response

Testing