<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj" -->

---
title: Laravel Sanctum 419 Error: CORS & CSRF Fix (Laravel 13)
description: A troubleshooting guide addresses the Laravel Sanctum 419 Page Expired and CSRF token mismatch errors that occur during SPA login with React, Vue, or Vite...
canonical: https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Laravel Sanctum 419 Error: CORS & CSRF Fix (Laravel 13) | daily.dev
og:description: A troubleshooting guide addresses the Laravel Sanctum 419 Page Expired and CSRF token mismatch errors that occur during SPA login with React, Vue, or Vite...
og:url: https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj
og:image: https://api.daily.dev/og/posts/7ySfvN9BJ.png
og:image:alt: Laravel Sanctum 419 Error: CORS & CSRF Fix (Laravel 13)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Sanctum 419 Error: CORS & CSRF Fix (Laravel 13)

**[Medium](https://daily.dev/sources/medium_js)** · 9 min read · 0 upvotes · 0 comments

## Summary

A troubleshooting guide addresses the Laravel Sanctum 419 Page Expired and CSRF token mismatch errors that occur during SPA login with React, Vue, or Vite frontends. It breaks down the five pieces that must align: stateful Sanctum domains, stateful API middleware in bootstrap/app.php, credentialed CORS configuration, session cookie domain settings, and correct Axios cookie/XSRF handling. It explains why requests succeed in Postman but fail in browsers, warns against common bad fixes like disabling CSRF or allowing all CORS origins, and covers architecture concerns when frontend and API live on unrelated domains (e.g., Vercel vs a custom API domain). Includes a diagnostic checklist and an FAQ section.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@blogs-world/laravel-sanctum-419-error-cors-csrf-fix-laravel-13-a692135e9447>

## Questions this post answers

### Why does Laravel Sanctum return a 419 error during SPA login?

A 419 response means Laravel could not validate the CSRF token tied to the user's session. In Sanctum SPA authentication, this typically stems from a missing or mismatched CSRF cookie, incorrect stateful-domain configuration, CORS not allowing credentials from the exact frontend origin, or the frontend failing to send cookies and the X-XSRF-TOKEN header correctly.

_Save this checklist on daily.dev so the next Sanctum CSRF debugging session goes faster._

### How do I configure SANCTUM_STATEFUL_DOMAINS for a Vite dev server on localhost:5173?

Set SANCTUM_STATEFUL_DOMAINS to the host and port exactly as the browser sees it, for example localhost:5173, not a full URL with https://. Treat localhost, localhost:5173, 127.0.0.1, and 127.0.0.1:5173 as distinct values, since Sanctum and the browser do not consider them interchangeable, and mixing them causes stateful-domain mismatches.

_Developers wiring up Laravel Sanctum locally can bookmark configuration details like this on daily.dev._

### Can a Laravel Sanctum SPA authenticate when the frontend is on Vercel and the API is on a different domain?

It works poorly because Sanctum's first-party SPA authentication assumes the frontend and API share the same top-level domain, like app.example.com and api.example.com. A frontend on project.vercel.app and an API on api.example.com are unrelated domains, so adding CORS entries alone won't make cookie authentication reliable; a custom frontend subdomain, token-based auth, or a backend-for-frontend architecture is recommended instead.

_Teams choosing an auth architecture for split-domain SPAs can track trade-offs like these on daily.dev._

## Similar posts on daily.dev

- [CSRF from Scratch: Browser Mechanics, Attacks, and Spring Security Implementation \[Full Handbook\]](https://daily.dev/posts/csrf-from-scratch-browser-mechanics-attacks-and-spring-security-implementation-full-handbook--4km8mrcii) · freeCodeCamp · 17 upvotes · 3 comments
- [CSRF Attack Explained: Mechanics, Real Exploits, and How to Test for It](https://daily.dev/posts/csrf-attack-explained-mechanics-real-exploits-and-how-to-test-for-it-lkzyruhyf) · Latest Hacking News · 0 upvotes · 0 comments
- [CVE-2026-49215: CSRF Protection Bypass in symfony/ux-live-component: Accept Header is CORS-Safelisted \(Symfony Blog\)](https://daily.dev/posts/cve-2026-49215-csrf-protection-bypass-in-symfony-ux-live-component-accept-header-is-cors-safeliste-ryk4pkn1c) · Symfony · 0 upvotes · 0 comments
- [Session Cookies or Bearer Tokens?](https://daily.dev/posts/session-cookies-or-bearer-tokens--cf0ptuyhm) · The Miners · 0 upvotes · 1 comments
- [CSRF Protection without Tokens or Hidden Form Fields](https://daily.dev/posts/csrf-protection-without-tokens-or-hidden-form-fields-a651bvhew) · Hacker News · 0 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#php](https://daily.dev/tags/php), [#authentication](https://daily.dev/tags/authentication), [#laravel](https://daily.dev/tags/laravel)

[View this post on daily.dev](https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Laravel Sanctum 419 Error: CORS \u0026 CSRF Fix (Laravel 13)","url":"https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj"},"datePublished":"2026-09-11T13:05:30.524Z","dateModified":"2026-10-15T02:22:15.451Z","description":"A troubleshooting guide addresses the Laravel Sanctum 419 Page Expired and CSRF token mismatch errors that occur during SPA login with React, Vue, or Vite...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/87b59c95d7233296cc906a1d885108a8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/87b59c95d7233296cc906a1d885108a8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,php,authentication,laravel","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"Laravel Sanctum 419 Error: CORS \u0026 CSRF Fix (Laravel 13)"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/laravel-sanctum-419-error-cors-csrf-fix-laravel-13--7ysfvn9bj#faq","mainEntity":[{"@type":"Question","name":"Why does Laravel Sanctum return a 419 error during SPA login?","acceptedAnswer":{"@type":"Answer","text":"A 419 response means Laravel could not validate the CSRF token tied to the user's session. In Sanctum SPA authentication, this typically stems from a missing or mismatched CSRF cookie, incorrect stateful-domain configuration, CORS not allowing credentials from the exact frontend origin, or the frontend failing to send cookies and the X-XSRF-TOKEN header correctly. Save this checklist on daily.dev so the next Sanctum CSRF debugging session goes faster."}},{"@type":"Question","name":"How do I configure SANCTUM_STATEFUL_DOMAINS for a Vite dev server on localhost:5173?","acceptedAnswer":{"@type":"Answer","text":"Set SANCTUM_STATEFUL_DOMAINS to the host and port exactly as the browser sees it, for example localhost:5173, not a full URL with https://. Treat localhost, localhost:5173, 127.0.0.1, and 127.0.0.1:5173 as distinct values, since Sanctum and the browser do not consider them interchangeable, and mixing them causes stateful-domain mismatches. Developers wiring up Laravel Sanctum locally can bookmark configuration details like this on daily.dev."}},{"@type":"Question","name":"Can a Laravel Sanctum SPA authenticate when the frontend is on Vercel and the API is on a different domain?","acceptedAnswer":{"@type":"Answer","text":"It works poorly because Sanctum's first-party SPA authentication assumes the frontend and API share the same top-level domain, like app.example.com and api.example.com. A frontend on project.vercel.app and an API on api.example.com are unrelated domains, so adding CORS entries alone won't make cookie authentication reliable; a custom frontend subdomain, token-based auth, or a backend-for-frontend architecture is recommended instead. Teams choosing an auth architecture for split-domain SPAs can track trade-offs like these on daily.dev."}}]}
```

