Skip to main content

Endpoint

method
string
default:"POST"
HTTP Method
endpoint
string
default:"/logout"
API Endpoint

Authentication

This endpoint requires authentication (uses auth middleware). Include the session cookie in the request.

Request Body

No request body parameters required.

Response

status
number
default:"204"
No Content - Logout successful. Session has been invalidated.

Example Request

cURL
curl -X POST https://your-api.com/logout \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Cookie: laravel_session=your-session-cookie"
Next.js
const response = await fetch('http://localhost:8000/logout', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
  },
  credentials: 'include', // Important for session cookies
});

if (response.status === 204) {
  // Logout successful
  // Redirect to login page
}

Success Response

HTTP/1.1 204 No Content
Set-Cookie: laravel_session=; expires=Thu, 01 Jan 1970 00:00:00 GMT

Error Responses

Unauthenticated (401)

Returned when no valid session exists:
{
  "message": "Unauthenticated."
}

Notes

  • The user is logged out using Auth::guard('web')->logout()
  • The session is invalidated, destroying all session data
  • The CSRF token is regenerated for security
  • The session cookie is cleared in the response
  • After logout, the user must login again to access protected endpoints
  • This endpoint is safe to call even if the session has already expired

Build docs developers (and LLMs) love