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
MadMax7mo 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 Melons7mo ago
It's currently broken.. I created an issue but it keeps getting closed
Steve Melons
Steve Melons7mo 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
Yiannis7mo 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
More Posts
How to filter-out images beyond certain size before the upload?Hey there. I'm having a trouble with restricting the size of images before the upload. I am using NeTheo, why you never use Docker? Why you always use Cloud based solutions?Theo, why you never use Docker? Why you always use Cloud based solutions that will gonna cost money How to handle after form submit with Server Actions ?Hello, I'm looking for the best way to know the form is succesfully submitted and a succesful respoNext-Auth v5 lacking provider authorization paramsI'm working with t3-turbo which has next-auth v5 and I'm not able to set authorization params like `Seeking Advice for a T3 Stack Application: Separating tRPC from NextJSI am currently planning to develop a web application using a T3 stack that includes tRPC, NextJS, anUploadThing `<UploadDropzone />` ComponentI'd like to have my file listed when I use the `<UploadDropzone />` component How can I have access Database & Serverless : handle connection spikes ?Hey, I'm running a Nextjs side project on Vercel & Mongo Atlas. My ORM is Mongoose (yep, didn't leaConnecting: T3 - Drizzle - PG - AuthJs ( v5 beta)Hi all. Did anyone manage to get this to work together nicely? OR find a good How-To somewhere on User event logging solution with T3 stack?I'm building a pet project with the T3 stack and I want to log user events for debugging purposes. IPython with Uploadthing?Hey everyone, I recently started working on my own Next.js app, which I mixed together with Python.