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

Explore custom session data storage mechanisms #2000

Open
sodic opened this issue Apr 29, 2024 · 1 comment
Open

Explore custom session data storage mechanisms #2000

sodic opened this issue Apr 29, 2024 · 1 comment
Labels
enhancement New feature or request research

Comments

@sodic
Copy link
Contributor

sodic commented Apr 29, 2024

One of our Discord members did a great job explaining the feature, so I'll just link that conversation:

@sodic sodic added enhancement New feature or request research labels Apr 29, 2024
@Martinsos
Copy link
Member

Martinsos commented May 7, 2024

Some snippets from that Discord convo:

Hi everyone 😉 I'm exploring a possibility to develop my new project in WASP which looks really awesome! However, I've got a question related to auth and was not able to find the answer... In my case user can belong to multiple organisations and switch between them once logged in. I'd like to store the current org ID in session is there any way to do it? I've been using blitz in my previous projects and it has ctx.session.$setPublicData() which is neat (https://blitzjs.com/docs/session-management#customize-session-public-data-in-typescript). Is there any alternative to this in WASP land? Thanks in advance!

Hi @sodic thanks for getting back! To be honest, I've never checked how it's done under the hood (until now) as it comes with a convenient API and just works 🙂 Blitz provides the following APIs:

  • ctx.session.$setPublicData() or setPublicDataForUser() to set public session data in the server side
  • it persists data in the DB sessions table as a json object and also sends back the updated public data in the response cookie as a base64 token which is persisted in both cookies and local storage
  • public session data could be accessed via useSession() in the front-end and e.g. ctx.session.orgId in the back-end

I found it really helpful in some use cases (user roles, multiple orgs per user, etc.). Of course, it's not a show stopper for me as I can implement some alternative myself but it might be a nice addon to WASP. I hope you'll find this useful too. I'm new to WASP but so far so good, nice work guys! 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request research
Projects
None yet
Development

No branches or pull requests

2 participants