Add rest of User prisma table types and data to nextauth session in auth.ts

Hi, how can I add all the user data to the session including user table specified values and not just nextAuth? My current setup in the scaffolded T3 auth.ts is the following:
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: number;
gender: boolean | null;
birthdate: string | null;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
}
}
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: number;
gender: boolean | null;
birthdate: string | null;
// ...other properties
// role: UserRole;
} & DefaultSession["user"];
}
}
/**
* 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,
...user,
id: parseInt(user.id)
},
}),
},
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
LinkedInProvider({
clientId: env.LINKEDIN_CLIENT_ID,
clientSecret: env.LINKEDIN_CLIENT_SECRET,
}),
/**
* ...add more providers here.
*
* Most other providers require a bit more work than the Discord provider. For example, the
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
*
* @see https://next-auth.js.org/providers/github
*/
],
pages: {
signIn: '/auth/signin'
}
};
/**
* 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,
...user,
id: parseInt(user.id)
},
}),
},
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
LinkedInProvider({
clientId: env.LINKEDIN_CLIENT_ID,
clientSecret: env.LINKEDIN_CLIENT_SECRET,
}),
/**
* ...add more providers here.
*
* Most other providers require a bit more work than the Discord provider. For example, the
* GitHub provider requires you to add the `refresh_token_expires_in` field to the Account
* model. Refer to the NextAuth.js docs for the provider you want to use. Example:
*
* @see https://next-auth.js.org/providers/github
*/
],
pages: {
signIn: '/auth/signin'
}
};
Is this the correct way to add the prisma table colum types and data to the session?
Solution:
Hi, how can I add all the user data to the session including user table specified values and not just nextAuth? My current setup in the scaffolded T3 auth.ts is the following: ```TS...
Jump to solution
4 Replies
nexxel
nexxel11mo ago
Create T3 App
NextAuth.js 🚀 Create T3 App
The best way to start a full-stack, typesafe Next.js app.
nexxel
nexxel11mo ago
Create T3 App
NextAuth.js 🚀 Create T3 App
The best way to start a full-stack, typesafe Next.js app.
nexxel
nexxel11mo ago
these two links might help
Mads
Mads11mo ago
Thank you very much @nexxel I actually found out I did it correctly, or everything works at least, so I will just go ahead and mark my own code as the solution.