Next Auth Drizzle Adapter does not include extra columns (fields)

auth.ts

providers: [
    GoogleProvider({
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
      profile(profile: GoogleProfile) {
        return {
          id: profile.sub,
          name: profile.name,
          email: profile.email,
          image: profile.picture,
          username: removeEmailDomain(profile.email) ?? profile.email,
        };
      },
    }),


I have a schema for the user table with username field. When I try to add the username field in the profile callback as initial data for user creation, the Drizzle adapter doesn't include the username field, and instead returns default fields only. Is there a way to fix this?
Solution
Found a workaround:
https://github.com/nextauthjs/next-auth/pull/8561

auth.ts

export const authOptions {
...
  adapter: {
    ...(DrizzleAdapter(db, createTable) as Adapter),
    // @ts-expect-error drizzle adapter does not include extra columns
    async createUser(data) {
      return await db
        .insert(users)
        .values({ ...data, id: crypto.randomUUID() })
        .returning()
        .then((res) => res[0] ?? null);
    },
  },
GitHub
☕️ Reasoning

In other adapters, the adapter returns the entire table so if you have additional fields they will also be returned when the adapter queries the table. A good example here is if your ...
Was this page helpful?