From 53e423100f184e2a4a0ecfa4660d71280eff7aaa Mon Sep 17 00:00:00 2001 From: Mustafa Date: Thu, 30 Jul 2026 12:23:12 +0300 Subject: [PATCH] fix: NextAuth type augmentation for session.user.role --- lib/auth.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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 },