Next.js Discord

Discord Forum

Need help with next-auth drizzle adapter (getting role undefined)...

Unanswered
Siricid woodwasp posted this in #help-forum
Open in Discord
Avatar
Siricid woodwaspOP
interface UserRole {
  role: "user" | "admin";
}

declare module "next-auth" {
  interface Session extends DefaultSession {
    user: {
      id: string;
      // ...other properties
      role: UserRole;
    } & DefaultSession["user"];
  }

  interface User {
    // ...other properties
    role: UserRole;
  }
}

/**
 * Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
 *
 * @see https://next-auth.js.org/configuration/options
 */
export const authOptions: NextAuthOptions = {
  callbacks: {
    session: ({ session, user }) => ({
      ...session,
      user: {
        ...session.user,
        id: user.id,
        role: user.role,
      },
    }),
  },
  //@ts-ignored
  adapter: DrizzleAdapter(db, mysqlTable),
  providers: [
    GoogleProvider({
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
    }),

3 Replies

Avatar
Siricid woodwaspOP
this is drizzle schema
export const users = mysqlTable(
  "user",
  {
    id: varchar("id", { length: 255 }).notNull().primaryKey(),
    name: varchar("name", { length: 255 }),
    email: varchar("email", { length: 255 }).notNull(),
    emailVerified: timestamp("emailVerified", {
      mode: "date",
      fsp: 3,
    }).default(sql`CURRENT_TIMESTAMP(3)`),
    image: varchar("image", { length: 255 }),
    tenantId: varchar("tenantId", { length: 255 }),
    role: mysqlEnum("role", ["user", "admin"]).default("admin"),
  },
  (user) => ({
    emailIdx: index("email_idx").on(user.email),
    tenantIdIdx: index("tenantId_idx").on(user.tenantId),
  }),
);
at drizzle adapter im getting

 Type AdapterUser
 is not assignable to type Awaitable<AdapterUser> 
Property 'role'   is missing in type
Avatar
Siricid woodwaspOP
Can someone look into this please I cant figure this out..