4

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
2
  • can you provide .env configuration for Sanctum? Commented Apr 15, 2020 at 17:49
  • @ShahadatHossain Edited Commented Apr 15, 2020 at 18:07

1 Answer 1

2

Try to add Referer header to fetch request

For example:

fetch(url, {
  credentials: 'include',
  headers: {
    Referer: 'localhost'
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.