Error: The field "phone_number" does not exist in the "user" schema

First things first. I'm new to better-auth and drizzle. So advanced sorry if I'm doing anything dumb

I'm getting the above error when I try to sign up my user, even when my "user" schema does have the "phone_number" field. Below is the
user
schema
export const user = pgTable("user", {
  id: text("id").primaryKey(),
  name: text("name").notNull(),
  email: text("email").notNull().unique(),
  emailVerified: boolean("email_verified").default(false).notNull(),
  phoneNumber: text("phone_number").notNull(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
  updatedAt: timestamp("updated_at").defaultNow().notNull(),
});


Below is my Better-Auth client
export const authClient = createAuthClient({
  plugins: [inferAdditionalFields<typeof auth>()],
});


I also have specified additionalFields in the auth instance
export const auth = betterAuth({
  user: {
    additionalFields: {
      phoneNumber: {
        type: schema.user.phoneNumber.dataType,
        required: schema.user.phoneNumber.notNull,
        fieldName: schema.user.phoneNumber.name,
      },
    },
  },
  emailAndPassword: {
    enabled: true,
  },
  database: drizzleAdapter(db, {
    provider: "pg",
    schema,
  }),
});


My DB is in Neon, and even in Neon Cloud, I can see the "phone_number" field (attached)

What am I missing here?
image.png
Solution
issue was in the
user
schema. I declared the phoneNumber field as "phone_number" where both the names should be identical. I'm surprised why this didn't show a ts error if this isn't allowed. and why bunx @better-auth/cli generate command generated schema also had the same issue in many fields like createdAt and updatedAt
Was this page helpful?