Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brianetaveras's avatar

401 - Unauthorized Vue SPA session authentication.

401 Unauthorized trying to set up session auth with Laravel 8 and Sanctum.

I've tried every guide out there and saw all stack overflow solutions on this but haven't found a way to get the authentication to persist. I added the SANCTUM_STATEFUL_DOMAINS and SESSION_DOMAIN environment variables but still get the 401. I added the front-end call to get the CSRF-TOKEN cookie before my login call or any of the other calls.

Running out of ideas here. Anyone else with this issue?

0 likes
4 replies
brianetaveras's avatar

@jlrdw Thanks for replying. I set this up already and still can't get authenticated. :/

jrran90's avatar

Hi,

Have you checked your Kernel.php? app/Http/Kernel.php

Make sure you uncomment \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, coz by default it is commented out

'api' => [
    \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
    'throttle:api',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Please or to participate in this conversation.