fix: NextAuth type augmentation for session.user.role

This commit is contained in:
2026-07-30 12:23:12 +03:00
parent 1f29eead28
commit 53e423100f
+17 -2
View File
@@ -1,9 +1,24 @@
import NextAuth from 'next-auth'
import NextAuth, { DefaultSession } from 'next-auth'
import { PrismaAdapter } from '@auth/prisma-adapter'
import Credentials from 'next-auth/providers/credentials'
import bcrypt from 'bcryptjs'
import { prisma } from '@/lib/db'
// NextAuth type augmentation — session.user.role için
declare module 'next-auth' {
interface Session {
user: {
role?: string
} & DefaultSession['user']
}
}
declare module 'next-auth/jwt' {
interface JWT {
role?: string
}
}
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
@@ -31,7 +46,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
},
session({ session, token }) {
if (token && session.user) {
session.user.role = token.role as string
session.user.role = token.role
}
return session
},