fix: NextAuth type augmentation for session.user.role
This commit is contained in:
+17
-2
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user