How to add custom fields on Sign-up?
How do you add custom fields to client side functions like sign-up?
I am working on a sign-up form in nextjs app router and I have better-auth working with the basic email, password, name, etc. fields using:
const { data } = await authClient.signUp.email(
{
email: formData.email,
password: formData.password,
name: ${formData.firstName} ${formData.lastName},
callbackURL: "/dashboard",
}
);
However I want to add some custom fields for example "practiceName", and "role":
user: {
additionalFields: {
practiceName: {
type: "string",
required: false,
},
firstName: {
type: "string",
required: true,
},
lastName: {
type: "string",
required: true,
},
role: {
type: "string",
required: false,
defaultValue: "user",
input: false, // don't allow user to set role
},
},
},
I have found a way to do this on the server side: https://www.better-auth.com/docs/concepts/database#extending-core-schema
But the same logic doesn't seem to work for auth-client side.
So my question is how do I add additional custom fields on the client side? Or is it only possible on the server side?
Any help is appreciated!
Database | Better Auth
Learn how to use a database with Better Auth.
1 Reply
Solution
TypeScript | Better Auth
Better Auth TypeScript integration.