41

How to set withCredentials=true to fetch which return promise. Is the following correct :

fetch(url,{
   method:'post',
   headers,
   withCredentials: true
});

I think the MDN documentation talked about everything about http-requesting except this point: withCredentials

Abdennour TOUMI
  • 76,783
  • 33
  • 229
  • 231

1 Answers1

86

Got it here :

  credentials: 'include'

and not

  withCredentials: true
Abdennour TOUMI
  • 76,783
  • 33
  • 229
  • 231
  • 1
    It's also in the [official spec](https://fetch.spec.whatwg.org/#cors-protocol-and-credentials) with an XHR example – CodingIntrigue Nov 11 '16 at 09:00
  • 3
    Anyone having issues with adding this config to fetch and still not getting a request cookie sent after logging in? – William Chou Dec 05 '19 at 22:16
  • 2
    It is also could be neccesary to add header `'Access-Control-Allow-Credentials': true` to the server response – Sdwdaw Apr 27 '20 at 12:50