Laravel Sanctum: {"message":"Unauthenticated."} 401 on API / SPA requests
A request to a auth:sanctum route had no valid token or session, so Laravel returned 401.
Unauthenticated. 401 Laravel SanctumIlluminate\Auth\AuthenticationException: Unauthenticated.Sanctum 401 Unauthenticated SPAauth:sanctum Unauthenticated Meaning
For token auth send Authorization: Bearer TOKEN and Accept: application/json. For SPA auth call /sanctum/csrf-cookie first, set withCredentials, configure SANCTUM_STATEFUL_DOMAINS, SESSION_DOMAIN and CORS supports_credentials. Missing Accept: application/json yields a redirect to /login instead.
Common causes
- No bearer token or wrong header
- SPA missing csrf-cookie call / withCredentials
- Domain not in SANCTUM_STATEFUL_DOMAINS
- SESSION_DOMAIN/cookie settings wrong
- Token revoked or expired
⚡ Quick fix
- Send
Accept: application/jsonandAuthorization: Bearer ... - SPA: call
/sanctum/csrf-cookiefirst and setSANCTUM_STATEFUL_DOMAINS - Check CORS
supports_credentials => true
Detailed fix by platform
Linux
curl -H "Accept: application/json" -H "Authorization: Bearer TOKEN" https://app.test/api/user
How to diagnose
- Mode — Token or SPA?
- Headers — Accept/Authorization?
- Domains — Stateful config?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 403 This action is unauthorized Laravel: Illuminate\Auth\Access\AuthorizationException: This action is unauthorized.
- 419 Page Expired Laravel: 419 Page Expired (CSRF token mismatch)
- 422 Unprocessable Entity: The given data was invalid Laravel: {"message":"The given data was invalid.","errors":{"email":["The email field is required."]}} (422)
Most viewed in Laravel
- MassAssignmentException Laravel: Illuminate\Database\Eloquent\MassAssignmentException: Add [x] to fillable property to allow mass assignment
- The GET method is not supported for route Laravel: The GET method is not supported for route x. Supported methods: POST (MethodNotAllowedHttpException)
- Route [login] not defined Laravel: Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026