1

I have my web page behind nginx proxy with basic auth set.

Web page uses ajax calls (using fetch) to get some data from same domain:

data = await fetch("/data");

When I access page, browser asks me to give user and password (std. browser feature), properly gets all resources (html, js, css), but then when my js uses fetch to get some data it gives me 401.

I was under impression that since fetch calls same domain, credentials I gave to the browser will be automatically used.

How to pass auth data I provided in browser to js fetch function?

Thanks!

pankleks
  • 693
  • 6
  • 14
  • Possible duplicate of [Using an authorization header with Fetch in React Native](https://stackoverflow.com/questions/30203044/using-an-authorization-header-with-fetch-in-react-native) – ben Mar 13 '18 at 10:32

1 Answers1

2

ok found solution, add:

credentials: "same-origin"

to init object passed to fetch.

pankleks
  • 693
  • 6
  • 14