Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Only: New session after each change to session #192

Open
Sotacan opened this issue Dec 23, 2019 · 0 comments
Open

Firebase Only: New session after each change to session #192

Sotacan opened this issue Dec 23, 2019 · 0 comments

Comments

@Sotacan
Copy link

Sotacan commented Dec 23, 2019

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 {}; } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant