W
Wasp-lang•2mo ago
blair

Modify data in `onBeforeSignup` hook

Pretty much the title. Is this possible? My signup flow requires a key linked to a third party service, and the goal was to gather data via that service's API before inserting it into the database. I've got properties on my User model that I don't include in my auth flow for obvious reasons - what's the go here? Is there a good option here besides making the data optional and inserting it in an onAfterSignupHook instead? I presume I'll need to hit the api twice if so - once in onBeforeSignup to verify, and once again in onAfterSignup to add additional properties.
8 Replies
kapa.ai
kapa.ai•2mo ago
Hi @blair. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information about modifying data in the onBeforeSignup hook in Wasp. However, Wasp does provide ways to customize the signup process, including defining extra fields in the User entity and customizing the SignupForm. You can also define userSignupFields to set extra fields on the User during the signup process. For more detailed information, you might find the following resources helpful: - Customizing the Signup Process (https://wasp-lang.dev/docs/auth/overview#customizing-the-signup-process) - Defining Extra Fields (https://wasp-lang.dev/docs/auth/overview#1-defining-extra-fields) - User Signup Fields (https://wasp-lang.dev/docs/auth/social-auth/github#usersignupfields-extimport) Please consult the official Wasp documentation or community for more specific guidance on your use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
martinsos
martinsos•2mo ago
Sorry for such a late response @blair -> yeah, I think you analyzed that right! It also sounds from this like we might want to make the onBeforeSingup hook a bit more flexible - it would be cool if you could return data from it, and that data would be added to the user during the signup, which seems to be what you need here -> you want to use onBeforeSignup hook to get some extra info about user from the external API and enrich it with that data. @miho what do you thikn about this one? Should we looking into supporting such use case?
blair
blairOP•2mo ago
No worries and thanks for the response!
MEE6
MEE6•2mo ago
Wohooo @blair, you just became a Waspeteer level 1!
miho
miho•2mo ago
Hey, there is userSignupFields concept that enables you to add extra fields on the user object: https://wasp-lang.dev/docs/auth/overview#1-defining-extra-fields
Overview | Wasp
Auth is an essential piece of any serious application. That's why Wasp provides authentication and authorization support out of the box.
martinsos
martinsos•2mo ago
@miho but he wants to do a fetch from external API, to get more info about you, prior to signup, and then add that to the user during the singup, if I got it right, and even look at that data to see if signup is happening or not I believe?
miho
miho•2mo ago
The fields in userSignupFields can be async + you can throw a HttpError to prevent the sign up from happening 🙂 sounds perfect for the use case
martinsos
martinsos•2mo ago
@miho oh right that makes sense! I guess the only thing missing is that there is no central place to do fetching once for all the fields, if there is shared "fetch" to perform. One could do it by impelenting some kind of a singleton though, or well really just a single promise that all resolve, but still, that would probably be nice. But I think we talkeda bout that already.
Want results from more Discord servers?
Add your server