JavaScript Fetch Send cookies


The fetch function does not send cookies by default. There are two possible ways to send cookies:

  1. Only send cookies if the URL is on the same origin as the calling script.
fetch('/login', {
    credentials: 'same-origin'
  1. Always send cookies, even for cross-origin calls.
fetch('', {
    credentials: 'include'