Getting role undefined in session even though it exist in db

interface UserRole {
role: "pleb" | "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,
}),
interface UserRole {
role: "pleb" | "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,
}),
4 Replies
MadMax
MadMax12mo ago
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),
}),
);
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
ts Type AdapterUser
is not assignable to type Awaitable<AdapterUser>
Property 'role' is missing in type

ts Type AdapterUser
is not assignable to type Awaitable<AdapterUser>
Property 'role' is missing in type

Steve Melons
Steve Melons12mo ago
It's currently broken.. I created an issue but it keeps getting closed
Steve Melons
Steve Melons12mo ago
GitHub
DrizzleAdapter overwrites custom tables with defaults · Issue #9296...
Adapter type @auth/drizzle-adapter Environment System: OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa) CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K Memory: 11.79 GB / 15.49 GB Container: Yes ...
Yiannis
Yiannis12mo ago
I found that the error goes away if you make any additions to the User interface optional
Want results from more Discord servers?
Add your server