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!

1

1 Answer 1

2

ok found solution, add:

credentials: "same-origin"

to init object passed to fetch.

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.