koajs / koajs/session

Firebase Only: New session after each change to session

Open
#192 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
908
Forks
115
PR merge metrics
No merged PRs in 30d

Description

### Overview
I'm trying to host the Koa app on Firebase Cloud Functions + Hosting through url rewrites and am having some trouble.

### Firebase issue
Firebase functions + firebase hosting with this causes issues. I noticed that data was getting saved to the provided store (firebase) but it would send a new uuid set-cookie header each time I change any data in the session.

One thing to note is firebase strips all cookies besides '__session' (though i did set this as the 'key' parameter which I assume would solve this)

**Suggested Solution:**

After looking at the library I am not quite sure what the issue is but I was able to create a temporary solution using firestore as the store. here is an example

`var KoaFirebaseSession = {
set: async (ctx, key, val) => {
var ourSessionKey = ctx.cookies.get("__session");
if(!ourSessionKey) {
ourSessionKey = uuidv4();
ctx.cookies.set("__session", ourSessionKey);
}
await firestoreAccess.set(ourSessionKey, {
[key]: val,
"_expire": Date.now() + COOKIE_CONFIG.maxAge,
"_maxAge": COOKIE_CONFIG.maxAge
});
},
get: async (ctx, key=null) => {
var ourSessionKey = ctx.cookies.get("__session");
if(ourSessionKey) {
var sessionData =
await firestoreAccess.get(ourSessionKey, COOKIE_CONFIG.maxAge);
if(key && sessionData && sessionData[key]) {
return sessionData[key];
} else if(sessionData) {
return sessionData;
}
}
return {};
}
}`

Contributor guide

Open the contributing guide

Research direction

The report names a Koa app running through Firebase Cloud Functions and Hosting, with a Firebase session store and __session cookie; no repository file or test is identified. Start by tracing session writes and cookie handling in that deployment, then reproduce repeated changes and verify the same session identifier persists; done means session data remains available without a new identifier on each change.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.