Cannot add a field "discordId" to my user object.

Hello people,

Sorry for my english.
I'm using the discord social provider to sign into my web application but the discord id is missing. So I want to add and here's what I have :

@/lib/auth.ts
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

import { db } from "@/db";
import * as schema from "@/db/schemas/auth-schema";

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: { ...schema },
  }),
  socialProviders: {
    discord: {
      clientId: process.env.DISCORD_CLIENT_ID,
      clientSecret: process.env.DISCORD_CLIENT_SECRET,
      // TODO: Update scopes
      scope: ["identify", "guilds"],
    },
  },
  user: {
    additionalFields: {
      discordId: {
        type: "string",
      },
    },
  },
});


@/db/schemas/auth-schema.ts
// ...
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(),
  image: text("image"),
  createdAt: timestamp("created_at")
    .$defaultFn(() => new Date())
    .notNull(),
  updatedAt: timestamp("updated_at")
    .$defaultFn(() => new Date())
    .$onUpdate(() => new Date())
    .notNull(),
  discordId: text("discord_id").unique(),
// ...
});


The field "discord_id" is now in the db but I don't know how to add the data into the session object (data that I can grab manually). My first thought was using callbacks but none of them does the job.

Thanks for the help!
Was this page helpful?