Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 401 Error in Laravel Sanctum/Airlock

I'm using Laravel as the backend for my Next JS app, and Sanctum to handle authentication.
I'm able to get the session authentication working just fine on the front end, but when I try to make requests to the API from the Node server for SSR, I get a 401 Unauthorized error.

Is there any way I can have both the client and Node server authenticating?

I'm running the API on localhost:8000 and the Next server on localhost:3000. I overloaded my env. with stateful domains in an attempt to get it to work:

SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:3000,localhost,localhost:8000,https://localhost:8000,https://localhost,http://localhost,http://localhost:8000
like image 364
curtisupshall Avatar asked Oct 27 '25 23:10

curtisupshall


1 Answers

Try to add Referer header to fetch request

For example:

fetch(url, {
  credentials: 'include',
  headers: {
    Referer: 'localhost'
  })
like image 159
ComixRu Avatar answered Oct 29 '25 14:10

ComixRu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!