I have a Laravel API and I implemented authentication with Laravel Sanctum and I am using homestead. I am trying to connect my Nuxt SSR frontend. Currently, I am experiencing an issue that I don't seem to understand and I have searched but can see any similar issue anyway.
The issue is that I can't even register a user from my Nuxt application. I get CSRF token mismatch error when I make a request to the register route.
- API domain:
api.myapp.test - Frontend domain:
myapp.test:3000
Sending a POST request to http://api.myapp.test/v1/register return a CSRF token mismatch error.
Is there something I am not getting right?
Below are my Laravel configs:
cors.php
return [
'paths' => ['v1/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];
session.php
[
'domain' => '.myapp.test',
]
sanctum.php
return [
'stateful' => [
'myapp.test:3000', 'api.myapp.test'
],
];
I am using nuxt/axios in my frontend.
nuxt.config.js
{
// Even if I remove the credentials property, is still does not work
axios: {
credentials: true
},
}
I am really confused because I don't get the error when I make the same request from Postman.