Type Custom Session and JWT Fields
If using TypeScript and adding id, role, or provider, augment the NextAuth types so the compiler matches runtime behavior.
File: `types/next-auth.d.ts`
import "next-auth";
declare module "next-auth" {
interface Session {
user: {
id: string;
role: string;
name?: string | null;
email?: string | null;
image?: string | null;
};
provider?: string | null;
}
interface User { role?: string; }
}
declare module "next-auth/jwt" {
interface JWT {
userId?: string;
role?: string;
provider?: string;
}
}💡 Ensure the declaration file is included by
tsconfig.json. Adjust optional fields to match your actual callbacks.