How to save custom fields (like address) in my database when admin creates a User?

I’m using the admin Plugin to create users. When an admin create a user, I need to save address data in my own database table (Address model). i tried to add the address field the data
const { error } = await admin.createUser({
name: `${values.firstName} ${values.lastName}`,
email: values.email,
password: password,
data: {
address: {
country: "Germany",
street: "Hauptstraße 1",
postalCode: "10247",
city: "Berlin",
},
},
});
const { error } = await admin.createUser({
name: `${values.firstName} ${values.lastName}`,
email: values.email,
password: password,
data: {
address: {
country: "Germany",
street: "Hauptstraße 1",
postalCode: "10247",
city: "Berlin",
},
},
});
My Prisma Schema:
model User {
id String @id @default(cuid())

name String
email String @unique
emailVerified Boolean @default(false)

forcePasswordChange Boolean @default(false)

address Address?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

sessions Session[]
accounts Account[]

twoFactorEnabled Boolean?
twofactors TwoFactor[]

role String?
banned Boolean?
banReason String?
banExpires DateTime?

@@map("user")
}
model Address {
id String @id @default(cuid())
street String
city String
state String?
postalCode String
country String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique

@@map("address")
}
model User {
id String @id @default(cuid())

name String
email String @unique
emailVerified Boolean @default(false)

forcePasswordChange Boolean @default(false)

address Address?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

sessions Session[]
accounts Account[]

twoFactorEnabled Boolean?
twofactors TwoFactor[]

role String?
banned Boolean?
banReason String?
banExpires DateTime?

@@map("user")
}
model Address {
id String @id @default(cuid())
street String
city String
state String?
postalCode String
country String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @unique

@@map("address")
}
3 Replies
skidy
skidy2w ago
Database | Better Auth
Learn how to use a database with Better Auth.
Patrick
PatrickOP2w ago
yes but i think this is only for users who register manually
Ping
Ping2w ago
@Patrick pass data
No description

Did you find this page helpful?