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
Try to add Referer header to fetch request
For example:
fetch(url, {
credentials: 'include',
headers: {
Referer: 'localhost'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With