2
votes

So I've been building a projet based on laravel. I'm building on a SPA foundation with sanctum as my authorization package. It works perfectly. Then I deploy the project to the server and everytime I try to login there is a 404 error on /sanctum/csrf-cookie. How could this happen? Is it because the SanctumServiceProvider not working.

This is the error image

3
But it works perfectly on localhost with SESSION_DDRIVER=file. Why is that a problem lad? - Agustinus Michael Varian
nope, the session domain is configurated to my host - Agustinus Michael Varian
It works on .test domain on my local development environment - Agustinus Michael Varian
done, i've put it in the thread - Agustinus Michael Varian
nope the project is on root folder... app is just a route inside my spa - Agustinus Michael Varian

3 Answers

1
votes

The problem is when you define sanctum prefix, the route become something else like this:

enter image description here

you can check your routes with : php artisan route:list

as you can see the /sanctum/ is removed and when you check the route /sanctum/csrf-cookie it will not be and throws 404 error. So you have two options:

  • add this prefix: 'prefix' => 'api/v1/sanctum'
  • or
  • change GET call to api/csrf-cookie
0
votes

I solved this issue by adding:

AllowOverride All

to the apache directory config

-2
votes

Add in config/cors.php

'paths' => ['*']