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). I even installed a new browser (Opera) to see if the program is working there, but to no avail.

It turns out Canary includes the credentials (cookie) even it is not explicitly specified in fetch's options. To make fetch work on all browsers, add credentials: 'include' option explicitly.

await fetch('urlHere', {credentials: 'include'});