Best approach for associating pre-registration data with user accounts after Email/Password + social
Hello everyone, I need some advice on the best procedure to implement this functionality:
I'm developing a system where users answer questions before registering. The responses are saved in the database with a temporary ID generated by the client and stored locally. Later, when the user completes registration (using Email & Password or social login methods), I want to associate those previously saved responses with the newly created user account.
What's the most correct way to handle this association?
Thanks in advance for your suggestions!
3 Replies
Wohooo @mario.p, you just became a Waspeteer level 3!
Hi @mario.p. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, there are a few approaches you could use to associate pre-registration data with user accounts after registration in Wasp. Here's what I recommend:
Using
userSignupFields
for Custom Signup Process
Wasp allows you to customize the signup process using userSignupFields
, which lets you save extra fields during user registration:
1. You could store the temporary ID from the client as part of the user signup data
2. Then use this ID to associate the pre-registration responses with the user account
For both email/password and social login methods, you can define custom userSignupFields
to handle this association:
Then after signup, you could run a query to associate the responses with the new user account using this ID.
Using localStorage for Temporary Storage
Another approach mentioned in the knowledge sources is using localStorage:
1. Store the temporary ID in localStorage when users answer questions
2. After successful registration/login, retrieve this ID from localStorage
3. Make a server action call to associate the responses with the user account
As mentioned in a Discord support thread: "When people land on the login page, save the query params in the localStorage
. After the login is completed, on the redirect page you retrieve the data from the localStorage
" Link to Discord thread.
Custom Post-Registration Hook
While not fully implemented yet, there's an open GitHub issue about adding hooks after login/sign-in to execute custom server code: Add hooks after login / sign-in issue. This would be the ideal solution for your use case, but since it's still an open issue, you'll need to use one of the alternative approaches for now.
Recommendation
The most robust approach with current Wasp capabilities would be:
1. Use userSignupFields
to pass the temporary ID during registration
2. Create a server action that associates pre-registration data with the user account
3. Call this action immediately after successful registration/login
This approach works with both email/password and social login methods, giving you a consistent way to handle the association regardless of the authentication method used.
Hope this helps with your implementation!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @mario.p, 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?Thanks!