How to add more keys to session with next auth

how do i add more keys to the session which next auth creates thank you
2 Replies
Xaohs
Xaohs2y ago
You can extend the default types of next auth by declaring a .d.ts file. Something like this which is also used in t3stack iirc:
declare module "next-auth/jwt" {
/** Returned by the `jwt` callback and `getToken`, when using JWT sessions */
interface JWT {
id: string;
}
}

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the
* `SessionProvider` React Context and trpc context
*/
interface Session {
user?: {
id: string;
} & DefaultSession["user"];
}

/** Passed as a parameter to the `jwt` callback */
interface User {
}
}
declare module "next-auth/jwt" {
/** Returned by the `jwt` callback and `getToken`, when using JWT sessions */
interface JWT {
id: string;
}
}

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the
* `SessionProvider` React Context and trpc context
*/
interface Session {
user?: {
id: string;
} & DefaultSession["user"];
}

/** Passed as a parameter to the `jwt` callback */
interface User {
}
}
You can then assign these values at the callbacks in your [...nextauth].ts. Of course you should also add these params to your db
shu
shu2y ago
do u perhaps have a code base which uses this technique that i could reference? would be big help. even if not, thank you for the solution. thank you, i figured it out!
Want results from more Discord servers?
Add your server