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
- Clears server-side sessions (if any)
- Clears token in client-side cookies
- 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
- Tokens in cookies have an expiration time and will automatically expire even without active logout
- Frontend should clear all locally stored user information
- After logout, redirect to the login page