foal icon indicating copy to clipboard operation
foal copied to clipboard

Allow session stores to access information from the current request

Open luxaritas opened this issue 2 years ago • 1 comments

I'm implementing a multi-tenant app where each tenant has its own database, and sessions should also be split between each database. I've written a custom session store, but as I am passing the tenant ID as a path parameter, the session store has no way to determine which database to use. For now, I have to basically re-implement sessions.

luxaritas avatar Feb 01 '22 18:02 luxaritas

I actually found a different way around this than re-implementing sessions. What I did was when returning the token to the user on login, I formatted the token to include the tenant ID, and then in my session store's read method parsed it out. Then I also similarly serialized the user ID to include both the user ID and tenant ID, so that I could access it for save, update, and fetchUser operations. It's still a bit hacky and it would probably still be ideal to provide extra request-time data directly, but this is at least doable.

luxaritas avatar Feb 01 '22 19:02 luxaritas