SOS

Shane O'Sullivan's technical blog… really ties the room together

Archive for the ‘Cloud’ Category

Firebase strips all request cookies

Posted by Shane O'Sullivan on September 11, 2019

A painfully wasteful discovery today was that, when you are using Firebase Functions to serve your code, it strips all cookies from the request object.  The only hack around this is to use a specially named cookie, “__session” and fit any data you need into that.

For example, in the browser

document.cookie = “__session=some_value”;

and on the server

import {parse} from “cookie-parse”;

exports.myFunction = functions.https.onRequest((req, res) => {
const cookie = req.headers.cookie;
const sessionValue = parse(cookie)[“__session”];
console.log(“Should be some_value”, sessionValue);
});

Posted in Cloud, Firebase, Technical | Leave a Comment »

 
%d bloggers like this: