Wondering how to properly add credentials to a fetch call in a Netlify Function. Everything works great if I use axios, but fetch for some reason keeps giving me “Unauthorized” from my local dev server, and I can’t figure out the right combination of keys to send.
To be clear, I’m using httponly cookie to authorize, and axios adds easily with credentials: true
, but I’m interested in getting it to work with fetch.
So far I’m trying this:
const response = await fetch(url, {
headers: { Accept: 'application/json' },
credentials: 'include',
})
and it doesn’t work. Tried cross-site
, that doesn’t work. Tried adding code: 'cors'
and that didn’t work.
This is for a SPA running on a separate sub-domain from backend API server (both have the same domain origin).
If I can’t get a good answer here, what would be the issue with going back to axios
? Only asking because it seems like the default Netlify Functions use fetch and wondering why?