Ouro
Ouro
BABetter Auth
Created by Ouro on 5/19/2025 in #help
AdditionalFields not working as expected, Drizzle
So I'm at my wit's ends, having scoured the web for a similar issue and having tried every config combination imaginable. It's not clear from the docs what is exactly expected to work "out of the box", so I'm hoping I can get more direction here. What I'm trying to do: Simply extend the user object with a field.
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
schema: schema,
}),
user: {
additionalFields: {
onboardingCompleted: {
type: "boolean",
fieldName: "onboarding_completed",
required: false,
},
},
},
export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
schema: schema,
}),
user: {
additionalFields: {
onboardingCompleted: {
type: "boolean",
fieldName: "onboarding_completed",
required: false,
},
},
},
schema is coming from my drizzle schemas, namely:
export const user = pgTable(
"user",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
phone: text("phone").unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
onboardingCompleted: boolean("onboarding_completed")
.notNull()
.default(false),
},
(table) => [index("user_email_idx").on(table.email)]
);
export const user = pgTable(
"user",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
phone: text("phone").unique(),
emailVerified: boolean("email_verified").notNull(),
image: text("image"),
createdAt: timestamp("created_at").notNull(),
updatedAt: timestamp("updated_at").notNull(),
onboardingCompleted: boolean("onboarding_completed")
.notNull()
.default(false),
},
(table) => [index("user_email_idx").on(table.email)]
);
In my middleware, I make a call to /api/auth/get-session. When I look at the response, the user object never has the "onboardingCompleted" field. What's strange, is during my testing I tried messing around by changing the database field name to a typo ("onboardingCompleted2"), and if I do that, Better Auth reports an error that it cannot find the field. Unfortunately I don't think it's possible to log the better-auth queries and Neon doesn't log them either. So to some extent, the config has some effect, but somehow, it's not enough to flow into the get-session response. At this point, I know I can use the customSession hook to add the field manually myself, but this comes at the cost of an extra database round trip which is inefficient. What is going wrong here? Many thanks!
3 replies