Sunday, July 1, 2018

401 on all browsers except Chrome Canary

Encountered a weird case where the program works on Chrome Canary, and then causes http 401 unauthorized on all other browsers (Firefox, Safari, Chrome). I even installed a new browser (Opera) to see if the code is working there, but to no avail.

It turns out Chrome Canary automatically uses the credentials (cookie) even if credentials: 'include' is not passed to fetch's options parameter.

So to make fetch work on all browsers, instead of this:

await fetch('urlHere');

Pass credentials: 'include' option explicitly instead:
await fetch('urlHere', {credentials: 'include'});


No comments:

Post a Comment