I am using express-session
for managing sessions in my Express+NodeJS backend app. I am using Firebase for authentication and Cloud Run for hosting my server. Based on the documentation of Cloud Run hosting, the only cookie allowed is __session
. I got it working only if I explicitly set my cookie in my response when user signs in.
res.setHeader("Set-Cookie", req.session);
res.cookie(
"__session",
{ something: "something" },
{
expires: new Date(Date.now() + 900000),
httpOnly: true,
sameSite: "none",
secure: true,
}
);
res.setHeader("Cache-Control", "private");
However, what I am trying to achieve is I want to set this __session
cookie in my app initialization in index.js
and it works locally.
app.use(
session({
name: "__session",
secret: process.env.SECRET_SESSION_KEY,
resave: false,
saveUninitialized: true,
store: sessionStore,
cookie: {
maxAge: 1000 * 60 * 60 * 24,
httpOnly: true,
sameSite: process.env.NODE_ENV === "development" ? "lax" : "none",
secure: process.env.NODE_ENV === "development" ? false : true,
},
})
);
However, in my production app, the cookie is not being set in response headers and cookie storage. In theory, I am setting the cookie name to be __session
, but for some reason Firestore/Cloud Run strips it off. What am I doing wrong? Any help is appreciated, my third day trying to solve the issues.