diff --git a/lib/auth.ts b/lib/auth.ts index 5a2cec7..c5d50ee 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -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 },