Skip to main content
POST
/
api
/
logout
Logout User
curl --request POST \
  --url https://api.example.com/api/logout \
  --header 'Content-Type: application/json' \
  --data '
{
  "token": "<string>"
}
'
{
  "message": "<string>",
  "error": "<string>"
}
Logs out a user by invalidating their session token. The token is cleared from the database, making it unusable for future authenticated requests.

Request Body

token
string
required
The user’s current session token to invalidate.

Response

message
string
Success message confirming logout.
error
string
Error message if logout fails.

Status Codes

  • 200: Successfully logged out
  • 400: Missing token
  • 401: Invalid or expired token

Error Messages

  • "no token provided" - Token field is missing from request
  • "invalid token" - Token does not exist or has already been invalidated

Example Request

curl -X POST https://api.mirage.com/api/logout \
  -H "Content-Type: application/json" \
  -d '{
    "token": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"
  }'

Example Response

{
  "message": "logged out successfully"
}

Notes

  • The token is set to NULL in the database, completely invalidating it
  • After logout, the token cannot be used for any authenticated requests
  • Attempting to logout with an already-invalidated token will return a 401 error
  • This is a secure logout that ensures the session cannot be reused

Build docs developers (and LLMs) love