I need Laravel Sanctum to support both SPA and Mobile App (Bearer) authentication. The issue is that I can't get both to work in parallel.
The SPA works perfectly fine, but the mobile app throws a "CSRF token mismatch error" when calling any protected endpoints. The issue seems to be the Origin header.
I noticed that the production mobile app's Origin header is "http://localhost/". If in Postman I use that value as the Origin header, the endpoints throw the same CSRF token mismatch error.
If I change the Origin header to anything else, everything works perfectly.
These are the contents of my config/sanctum.php:
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
'%s%s',
'localhost,localhost:3000,localhost:8080,127.0.0.1,127.0.0.1:8000,::1',
env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : ''
))),
"localhost" is already there so I am not sure why the Bearer token auth fails when the Origin = "http://localhost"
I tried setting my .env SANCTUM_STATEFUL_DOMAINS to "http://localhost", and this makes the Mobile App work perfectly, but then it breaks the SPA.

