Dev Tools · 2h ago
Fix Laravel Sanctum 401s in Nuxt SSR by forwarding cookies
Server-side rendering in Nuxt causes 401 errors with Laravel Sanctum's SPA cookie auth because the server-side HTTP client lacks cookies, Origin headers, and proper URL resolution. The fix involves forwarding the incoming request's Cookie header and Origin via useRequestHeaders and useRequestURL. This ensures Sanctum recognizes the server-side request as stateful and authenticates it correctly.
Meridian48 take
A common SSR pitfall that's well-documented but easily missed — the fix is straightforward once you understand that server-side requests are essentially a different client.
Read the full reporting
Laravel Sanctum with Nuxt SSR: why the session disappears on the server →
DEV Community
laravel-sanctumnuxt-ssr