pankleks
pankleks

Reputation: 733

http fetch basic auth - use browser credentials

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!

Upvotes: 1

Views: 1193

Answers (1)

pankleks
pankleks

Reputation: 733

ok found solution, add:

credentials: "same-origin"

to init object passed to fetch.

Upvotes: 2

Related Questions