Cookie missing in HTTP request when using Fetch API

Debugging: a classic mystery game where you are the detective, the victim, and also the murderer.

Image for post
Image for post
Image source: Programmer Humor
import fetch from 'cross-fetch';fetch('/some-route', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: { /* some payload */ }
});
import 'cross-fetch/polyfill';fetch('/some-route', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: { /* some payload */ }
});

A bunch of users started getting 403s.

Image for post
Image for post
Image source: Know Your Meme
Image for post
Image for post
import 'cross-fetch/polyfill';fetch('/some-route', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: { /* some payload */ },
credentials: 'same-origin' // the fix
});

Written by

Right-brained techie passionate about coding, product, UX, and fun adventures with my family. Let’s connect on linkedin.com/in/suhanwijaya

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store