Skip to content
Advertisement

How to integrate React App With Laravel Sanctum on Apache2


I use React App on localhost:3000
For Laravel API I use apache2 from Laradock and site is: site.localhost
To authorize users I use Sanctum
Problem is I can not get cookies from sanctum/csrf-cookie (i got them in response header but they are not appear in cookies) and then got 419 code when i try to login via API My .env
SESSION_DRIVER=cookie
SESSION_DOMAIN=.localhost
SANCTUM_STATEFUL_DOMAINS=localhost:3000,site.localhost

And this is how i get XSRF token

    fetch("http://site.localhost/sanctum/csrf-cookie", {
            method: 'GET',
            headers: {'Content-Type': 'application/json'},
            credentials: 'include',
        });

Is this Sanctum configuration is ok ?

Advertisement

Answer

This is now solved.

  1. Add the following to /etc/hosts:

    127.0.0.1 example.com
    127.0.0.1 front.example.com
    
  2. Then configure apache for these domains.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement