Reputation: 1814
I have a request that I'm making via fetch(url)
. It doesn't seem like my cookies that I have are being passed along?
What is the canonical way of doing this? Should I pass document.cookie
to the fetch
request?
Upvotes: 0
Views: 201
Reputation: 400
Use credentials
in the options object passed to the second parameter:
fetch('url', {
credentials: 'include'
})
credentials
also takes same-origin
, which only sends cookies which match the domain of the URL requested.
Upvotes: 1
Reputation: 88086
You need credentials: 'include'
in the init object you pass as the second arg to fetch(…)
:
fetch(url, {
credentials: 'include'
})
Upvotes: 2