How to add custom Sign up field that refers another entity
I am trying to create a custom sign up where a User can select college and university through a drop down. This is my defineUserSignupFields method call:
All of these attributes exist in my User entity however I get this error:
Unknown arg
university
in data.university for type UserUncheckedCreateInput. Did you mean universityId
?
trying to use universityId/collegeId instead of university/college yields the same error but with typ UserCreateInput8 Replies
Hi @Suchitk. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error message you're seeing suggests that the
UserUncheckedCreateInput
type doesn't recognize the university
and college
fields. This could be because these fields are not directly part of the User
entity, but are related entities.
In Wasp, the defineUserSignupFields
function is used to define extra fields that need to be set on the User
during the sign-up process. The keys in the userSignupFields
object represent the field name, and the values are functions that receive the data sent from the client and return the value of the field. If the value that the function received is invalid, the function should throw an error.
Here is an example of how to define userSignupFields
:
(Source: Wasp Docs (https://wasp-lang.dev/docs/auth/social-auth/keycloak#api-reference))
However, the defineUserSignupFields
function and the userSignupFields
object are not designed to handle relations between entities. In your case, you're trying to connect the User
entity with the University
and College
entities during the sign-up process, which is not supported out of the box.
You might need to create a custom sign-up action to handle this. Unfortunately, the provided knowledge sources do not contain enough information on how to do this. I recommend checking the Wasp documentation or reaching out to the Wasp community for further assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Suchitk, 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?Your code seems to be on the right track, but if you could share your entities with me and I'll replicating the setup 🙂
I'd need your Signup page and your Wasp file (the important bits)
Hey here are the SignupPage and wasp file as requested, your help would be much appreciated!
I've tried doing this locally:
And it worked for me 😄
One thing that doesn't work - the initial set of the
dogId
value on load. I had to pick something in the <select>
to get the first value to be set properly.
Did you try outputing the data
to see what you actually receive from the client?Wow, Thank you so much for deconstructing the logic like this 😃 I have managed to get it to work based on the example that you have provided. The issue was mainly with how I was providing the ID from data as well as the initial set of ID on load.
Nice, I'm glad it worked 😊
@miho also thank from me ^^ couldn't figure it out without your help. That should be in the OpenSaaS Documentation
but important: dont forget the userSignupFields 😄