W
Wasp-langaslauris

Storing additional data in session

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!
K
kapa.aiβ€’16d ago
Hi @aslauris. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hello! Wasp's auth uses sessions to keep track of the logged-in user. The session is stored in localStorage on the client and in the database on the server source (https://wasp-lang.dev/docs/auth/overview#sessions). However, as of the current state of Wasp, there isn't a direct equivalent to Blitz's ctx.session.$setPublicData(). That said, Wasp does allow you to customize the signup process by defining extra fields. This could potentially be used to store additional information about the user, such as the current organization ID source (https://wasp-lang.dev/docs/auth/overview#1-defining-extra-fields). Additionally, there is an open issue on GitHub discussing the possibility of providing a managed client storage solution, which could potentially be used to store additional user-specific data source (https://github.com/wasp-lang/wasp/issues/1082). For more complex scenarios, you might consider setting up a custom Wasp API endpoint that can query the user info source (https://discord.com/channels/686873244791210014/1214656571787710474). Please note that these are potential solutions and might require additional customization to fit your specific use case. It's always a good idea to follow the ongoing discussions and updates in the Wasp community for the latest features and improvements. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @aslauris, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
M
mihoβ€’14d ago
@sodic another one to pick up when you have the time
F
Filipβ€’13d ago
Hey @aslauris, Wasp doesn't support this out of the box. But you can let me know how you'd want to use it (e.g., is it persistent in the database or just a property of a browser session that doesn't need to be stored anywhere) And we can come up with a way to best implement it Both for Wasp in the future and for you now πŸ™‚
A
aslaurisβ€’13d ago
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! πŸ˜‰
F
Filipβ€’13d ago
This is great stuff, @aslauris! Thanks for digging in and getting all the details. Yes, we definitely have no such system. Also, yes, you can 100% do this yourself (let me know if you need any help), but it's pretty manual at this point. I'll create a GitHub issue for exploring this system and link your message if that's OK with you πŸ™‚
A
aslaurisβ€’13d ago
Sure thing @sodic !
F
Filipβ€’13d ago
Here's the issue, it even got a nice round number: https://github.com/wasp-lang/wasp/issues/2000
A
aslaurisβ€’13d ago
Sweet ❀️
Want results from more Discord servers?
Add your server
More Posts
OAuth Login Error with Google Credentials in Local EnvironmentHello everyone, I need a bit of help. In my local environment, I've correctly set up the GOOGLE_CLIETypescript not validating included relationThis is likely due to my inexperience with typescript, but I've been trying to access a related propcustomize auth UI button shapeHi, I see there is an appearance to customize the color of the auth UI, how can I change the shape oStarlight missing trailing slashStarlight's sidebar doesn't include a trailing slash ("/") at the end of the URL, leading to a 301 rSuggested cookie consent plugin?I have been trying a few cookie consent plugins for React, but none seem to work well with Wasp (e.gpaypal & other payment gateway integrationI am curious if there is guideline/template for integration of other payment gateway apart from striGoogle Tag ManagerHey everyone, I am implementing Google Tag Manager according to the instructions (attached). The <hecustom http api endpointHello. I am following some of the documents for custom http api endpoint. 8 gave an 'api foobar' defIs it possible to customise titles of Auth component?I create an app in french, I can't let it in english. I saw I can customize the colors but that's noHow can I custom the verification email content?+ Can I use SendGrid template?failed to solve: process "/bin/bash -ol pipefail -c npm run build" did not complete successfully: exwhile deploying client on railway LinuxDatabase not started on setting up the projectI have just worked with Wasp-lang and trying to run the first project. The error occurs when I try terror schema.prisma:63Hi Guys, i get the following error when creating a new project in wasp it says schema.primsa is alreHow to change logo in google searchWhen I search for my website on google. The results show the logo for wasp on the left of the link iHow to replace wasp logo as favicon in tabI've deployed my website using wasp deploy fly deploy. In my localhost, I was able to replace the faWhat file contains the styles for the login and signup pageI'm trying to edit the styling of the Auth UI Component because it doesn't fit with the color schemeWhen using GitHub codespaces, how to setup Google Oauth for developmentWhen using GitHub codespaces, how to setup Google OAuth for development/I tried using "wasp ai" like this video https://www.youtube.com/watch?v=0 shows but it doesn't workGenerating plan (slowest step, usually takes 30 to 90 seconds)... Code agent failed with the http erOauth provider flow redirects to localhost:3001 instead of 3000I'm creating a new WASP app from scratch, I've added the Google Provider. My server by default runsGetPaginatedTransactions problem with query with decimalsHello I made simple object entity Transaction {=psl id Int @id