60

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
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

111

Got it here :

  credentials: 'include'

and not

  withCredentials: true
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • 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
  • 4
    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
  • 4
    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
  • @WilliamChou Me. https://stackoverflow.com/questions/75971278/sending-cookies-in-a-cross-origin-request Have spent days on this and still unresolved. – Old Geezer Apr 10 '23 at 02:20