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

ethar's avatar
Level 5

Laravel Sanctum SPA, Cant Save Cookies

i use Sanctum for Authentication, i use this code to get cookies

    const login = async (e) => {
        e.preventDefault();
        axios.defaults.withCredentials = true;
        axios.get('http://www.react.test/sanctum/csrf-cookie').then(response => {
            console.log(response);
        });
    }

in console.log data recived successfully, but when go to Application Tab ->Cookies -> im not found nothing. i make edit in cors.php

    'supports_credentials' => true,

note

laravel domain is http://www.react.test/

react domain is http://localhost:3000

0 likes
2 replies
alexios's avatar
alexios
Best Answer
Level 25

Laravel Sanctum approach:

In order to authenticate, your SPA and API must share the same top-level domain. However, they may be placed on different subdomains.

In your case, you have two different domains: localhost and react.test You have to change them to have the same domain: laravel.test and react.laravel.test

Also you need to know about proper session configuration in config/session.php:

'domain' => '.laravel.test'

The best way is to go through the documentation which does a great job of explaining how to configure SPA Authentication with Laravel Sanctum: https://laravel.com/docs/8.x/sanctum#spa-authentication

1 like

Please or to participate in this conversation.