W
Wasp-lang2mo ago
bmo

How to change how user is added to database.

Im using WASP SAAS template however i'm trying to change how a user is put into the database. I made a new table called person, and i'm trying to create this first and then attach it to the user as a foreign key.
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @bmo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To change how a user is added to the database in Wasp, you would need to modify the User entity and create a new entity for Person. You can then establish a relationship between these two entities. Here's a basic example of how you might define these entities:
entity User {
id Int @id @default(autoincrement())
personId Int
person Person @relation(fields: [personId], references: [id])
// Add your own fields below
// ...
}

entity Person {
id Int @id @default(autoincrement())
// Add your own fields below
// ...
}
entity User {
id Int @id @default(autoincrement())
personId Int
person Person @relation(fields: [personId], references: [id])
// Add your own fields below
// ...
}

entity Person {
id Int @id @default(autoincrement())
// Add your own fields below
// ...
}
In this example, User has a foreign key personId that references the id of a Person entity. However, please note that Wasp creates some entities behind the scenes for authentication, such as Auth, AuthIdentity, and Session. These entities are used to store the user's login credentials and you as the developer don't need to care about these entities most of the time. If you want to create a custom signup action, you will need to use the Auth and AuthIdentity entities directly (source (https://wasp-lang.dev/docs/auth/entities#entities-explained)). If you want to include extra fields in your signup process and save them in the User entity, you need to define the fields that you want saved in the database and customize the SignupForm (source (https://wasp-lang.dev/docs/auth/overview#customizing-the-signup-process)). For more complex modifications to the signup process, such as allowing users to define a custom username after they sign up with a social provider, you can follow the steps outlined in the Wasp documentation (https://wasp-lang.dev/docs/auth/social-auth/overview#overrides). Remember to update the database schema by running wasp db migrate-dev after making changes to your entities. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @bmo, 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?
miho
miho2mo ago
Wasp relies on having a "User" entity that it works with. You can name this entity however. And of course, in the post login hook, you can connect the "User" to the "Person" you created earlier: https://wasp-lang.dev/docs/auth/auth-hooks#executing-code-after-the-user-signs-up I guess you want to have some sort of flow before the user actually registers? Like a guest mode which you connect to the user later on?
Auth Hooks | Wasp
Auth hooks allow you to "hook into" the auth process at various stages and run your custom code. For example, if you want to forbid certain emails from signing up, or if you wish to send a welcome email to the user after they sign up, auth hooks are the way to go.
Want results from more Discord servers?
Add your server