How do I add more data to session?

import type { Role } from "@prisma/client";

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module "next-auth" {
interface Session extends DefaultSession {
user: DefaultSession["user"] & {
id: string;
// ...other properties
role: Role;
};
}

interface User {
// ...other properties
role: Role;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
},
}),
},
import type { Role } from "@prisma/client";

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module "next-auth" {
interface Session extends DefaultSession {
user: DefaultSession["user"] & {
id: string;
// ...other properties
role: Role;
};
}

interface User {
// ...other properties
role: Role;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
},
}),
},
This isn't working. Am I missing something?
1 Reply
Mike
Mike•9mo ago
Hey @Andrey, you may need to add the role to your session callback 😄
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role
},
}),
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role
},
}),
Want results from more Discord servers?
Add your server