D-Rek
D-Rek
TTCTheo's Typesafe Cult
Created by D-Rek on 11/20/2023 in #questions
Why do we do Session module-augmentation on both next.auth.d.ts and server/auth.ts
What's the difference between the two?
//In next.auth.d.ts we have:
declare module "next-auth" {
interface Session {
user: User & {
id: string;
};
}
}

//In server/auth.ts
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
}
}
//In next.auth.d.ts we have:
declare module "next-auth" {
interface Session {
user: User & {
id: string;
};
}
}

//In server/auth.ts
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
}
}
What's the purpose of the global next.auth.d.ts if we already have the augmented Session in the auth?
2 replies