NextAuth add additional property to session

Hi, I am trying to add "plan" to the session object that I can receive with the useSession() hook. I am using create-t3-app
...
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => {
console.log({ user, session });
return {
...session,
user: {
...session.user,
plan: user.plan,
id: user.id,
},
};
},
},
...
...
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => {
console.log({ user, session });
return {
...session,
user: {
...session.user,
plan: user.plan,
id: user.id,
},
};
},
},
...
But it is throwing an typescript error: TS2339: Property 'plan' does not exist on type 'AdapterUser'. It is working fine tough. Any tips?
Solution:
```ts import NextAuth from "next-auth" declare module "next-auth" { /**...
Jump to solution
3 Replies
barry
barry2y ago
Should be declared in the next-auth module too
Solution
barry
barry2y ago
import NextAuth from "next-auth"

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {}
}
import NextAuth from "next-auth"

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {}
}
This already exists somewhere in a t3 app
alts
alts2y ago
@barry Thanks! I added it to the session already, but had to create a User interface too:
interface User {
plan: string;
}
interface User {
plan: string;
}
Want results from more Discord servers?
Add your server