Prisma Adapter not generating Additional Fields for Organization

I had a lot of work with my config auth file, the modelNames work, the aditional fields for user work, but the custom field names and the additional fields are not being generates correctly using the prisma adapter:
1 Reply
Samira Costa
Samira Costa3mo ago
Oi @gabrielsuperti☭ , For it to work you need to do 2 things: - add all additional fields to the user table - add this user object to your authClient with the inferAdditionalFields plugin example of how I did it: auth-client.ts
export const auth = betterAuth({
user: {
fields: { name: 'firstName' },
additionalFields: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
language: { type: 'string', required: false },
terms: {
type: 'boolean',
required: true,
},
},
},
database: drizzleAdapter(dbClient, {
provider: 'pg',
schema,
}),
plugins: [],
});
export const auth = betterAuth({
user: {
fields: { name: 'firstName' },
additionalFields: {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
language: { type: 'string', required: false },
terms: {
type: 'boolean',
required: true,
},
},
},
database: drizzleAdapter(dbClient, {
provider: 'pg',
schema,
}),
plugins: [],
});
auth-schema.ts
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name"),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified")
.$defaultFn(() => false)
.notNull(),
image: text("image"),
createdAt: timestamp("created_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
updatedAt: timestamp("updated_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
username: text("username").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
language: text("language").default("pt").notNull(),
terms: boolean("terms").notNull(),
metadata: text("metadata"),
});
export const user = pgTable("user", {
id: text("id").primaryKey(),
name: text("name"),
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified")
.$defaultFn(() => false)
.notNull(),
image: text("image"),
createdAt: timestamp("created_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
updatedAt: timestamp("updated_at")
.$defaultFn(() => /* @__PURE__ */ new Date())
.notNull(),
username: text("username").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
language: text("language").default("pt").notNull(),
terms: boolean("terms").notNull(),
metadata: text("metadata"),
});
auth-client.ts
export const authClient = createAuthClient({
baseURL: env.AUTH_SERVICE_URL,
plugins: [
inferAdditionalFields({
user: {
firstName: { type: "string", required: true },
lastName: { type: "string", required: true },
language: { type: "string", required: false },
terms: {
type: "boolean",
required: true,
},
},
}),
emailOTPClient(),
nextCookies(),
organizationClient({
ac,
roles: {
owner,
doctor,
secretary,
},
}),
],
});
export const authClient = createAuthClient({
baseURL: env.AUTH_SERVICE_URL,
plugins: [
inferAdditionalFields({
user: {
firstName: { type: "string", required: true },
lastName: { type: "string", required: true },
language: { type: "string", required: false },
terms: {
type: "boolean",
required: true,
},
},
}),
emailOTPClient(),
nextCookies(),
organizationClient({
ac,
roles: {
owner,
doctor,
secretary,
},
}),
],
});
qualquer duvida, fique a vontade pra me mandar uma mensagem privada 🙂

Did you find this page helpful?