Skip to content

Logout

Interface Information

  • Endpoint: /api/auth/logout
  • Method: POST
  • Content-Type: application/json
  • Authentication Required: No

Request Parameters

No parameters.

Request Example

bash
curl -X POST http://localhost:3000/api/auth/logout \
  -H "Content-Type: application/json" \
  -b "auth_token=your_token_here"

Response Example

Success Response

json
{
  "success": true,
  "message": "Logout successful"
}

Function Description

  1. Clears server-side sessions (if any)
  2. Clears token in client-side cookies
  3. Resets user authentication status

Frontend Integration Example

javascript
async function logout() {
  const response = await fetch('/api/auth/logout', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    credentials: 'include'
  })
  
  const result = await response.json()
  
  if (result.success) {
    // Clear local user information
    localStorage.removeItem('user')
    sessionStorage.removeItem('user')
    
    // Redirect to login page
    window.location.href = '/admin/login'
  }
}

Notes

  1. Tokens in cookies have an expiration time and will automatically expire even without active logout
  2. Frontend should clear all locally stored user information
  3. After logout, redirect to the login page