Hi everybody,
I've already searched on this forum and on the internet a solution to my problem but I can't face why this is happening.
I need to use Laravel as API and a separate react application as frontend.
If i set up bearer token, and pass to Laravel in header everything is working, but i want to use cookie session.
Domains are: frontend.appname.local and development.appname.local
LARAVEL:
.env:
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
SESSION_DOMAIN=.appname.local
SANCTUM_STATEFUL_DOMAINS=development.appname.local
cors.php:
'supports_credentials' => true,
Kernel.php:
'api' => [
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
React:
axiosClient.defaults.withCredentials = true;
axiosClient.get(constants.CSRF_URL).then((csrf_response) => {
axiosClient
.post("/login", {
email,
password,
})
.then((response) => {}
)
})
where CSRF_URL = http://development.appname.local/sanctum/csrf-token
The login is ok, the cookie seems to be set in my browser (I can see it in the Application tab).
The error occurs when i try to perform another post request, and i get 401 unauthorized.
The cookie seems to be sent in this new post request:
Cookie: XSRF-TOKEN=eyJpdiI6IkJR............
Am i missing something?
Thanks!