Skip to content

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

Description

@Sotacan

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions