Using next-auth v5 and prisma role based authentication

Please consider the following auth.ts file located in the root of my project.
// auth.ts
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
secret: process.env.NEXTAUTH_SECRET,
adapter: PrismaAdapter(prisma),
providers: [
Discord({
clientId: process.env.DISCORD_CLIENT_ID ?? "",
clientSecret: process.env.DISCORD_CLIENT_SECRET ?? "",
}),
],
callbacks: {
authorized(params) {
return !!params.auth?.user;
},
},
});
// auth.ts
export const {
handlers: { GET, POST },
auth,
} = NextAuth({
secret: process.env.NEXTAUTH_SECRET,
adapter: PrismaAdapter(prisma),
providers: [
Discord({
clientId: process.env.DISCORD_CLIENT_ID ?? "",
clientSecret: process.env.DISCORD_CLIENT_SECRET ?? "",
}),
],
callbacks: {
authorized(params) {
return !!params.auth?.user;
},
},
});
When using the session from auth() in my front end, I only get access to the user's email, name, image - but I would like to have access to a database column isMember as defined in my Prisma Schema here:
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
isMember Boolean @default(false)
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
isMember Boolean @default(false)
}
Does anyone know how I can extend the sessions provider to be able to have access to the isMember value in my database? I hope to access this column value in middleware.ts to only allow users access. Please let me know if I can provide any other information. Thank you.
1 Reply
Ethan
Ethan11mo ago
Bumping Bumping. Still can’t seem to figure this out.
Want results from more Discord servers?
Add your server