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!
1 Reply
Ping
Ping2w ago
Hello, I understand your frustration. This is done intentionally for security reasons, it's valid to put potentially sensative information on the user table, so we do not expose anything in get-session even if it's defined in the additionalFields. I do recommend using the customSession plugin if you want that field exposed to the getSession response.

Did you find this page helpful?