Send cookies with fetch
Same-origin requests send cookies by default. Set credentials explicitly for other cases.
AJAX · Send cookies with fetchBeginner
fetch('/api/profile', { credentials: 'same-origin' }) // default: cookies for your own site
.then(function (r) { return r.json(); });
fetch('/api/private', { credentials: 'omit' }); // never send cookiescredentialscookiessessionfetch