Cookies not being stored with Fetch
You encountered an interesting case. The thing is that behavior of fetch
function is different rather than XMLHttpRequest
. To work with cookies in fetch
you should explicitly provide credentials
option.
fetch('http://127.0.0.1:4000/authorize-cookie', { method: 'POST', body: JSON.stringify({token: token}), credentials: 'same-origin', // <- this is mandatory to deal with cookies})
According to the article on MDN
Credentials: The request credentials you want to use for the request: omit, same-origin, or include. To automatically send cookies for the current domain, this option must be provided.