Missing field in session object with drizzle adapter

I'm using BetterAuth with the drizzle adapter in my next.js application and have added a custom isAdmin field to my user schema. Despite the field existing in my database and configuring additionalFields in BetterAuth, session.user does not include isAdmin when I log it. I've also attempted to use the inferAdditionalFields plugin on the client side, but it still doesn't appear in the session object. I'm looking for a solution to correctly include isAdmin in the session data.

here's my code for auth:
export const auth = betterAuth({
  secret: process.env.SECRET!,
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      user,
      verification,
      session,
      account,
    },
  }),
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: false,
  },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID! as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET! as string,
    },
  },
  plugins: [username()],
})

and here's my code for authClient:
export const authClient = createAuthClient({
  plugins: [
    usernameClient(),
    inferAdditionalFields({
      user: {
        isAdmin: {
          type: "boolean",
        },
      },
    }),
  ],
  baseURL: "http://localhost:3000",
});
export type Session = typeof authClient.$Infer.Session;
export const { signIn, signOut, signUp, useSession } = authClient;
image.png
image.png
Solution
Don't put the additional fields in the schema.
It should be at the
betterAuth
level.

Here is how it should be:
export const auth = betterAuth({
  secret: process.env.SECRET!,
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      user,
      verification,
      session,
      account,
    },
  }),
  user:{
    additionalFields: { 
          isAdmin: {
             type: "boolean",
             required: true,
             defaultValue: false,
             input: false
          },
      },
  },
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: false,
  },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID! as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET! as string,
    },
  },
  plugins: [username()],
})
Was this page helpful?