How do you add a new field to Session User in NextAuth using T3 stack?

I added this in my auth.ts
declare module 'next-auth' {
interface Session extends DefaultSession {
user: {
id: string;
} & DefaultSession['user'];
}

interface User extends DefaultUser {
credits: number;
}
}
declare module 'next-auth' {
interface Session extends DefaultSession {
user: {
id: string;
} & DefaultSession['user'];
}

interface User extends DefaultUser {
credits: number;
}
}
Then in my session callback
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
credits: user.credits,
},
}),
},
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
credits: user.credits,
},
}),
},
And still I am not being able to retrieve this credits field from the user table in my DB. Here's my user table created with Drizzle
export const users = createTable('user', {
id: varchar('id', { length: 255 }).notNull().primaryKey(),
name: varchar('name', { length: 255 }),
email: varchar('email', { length: 255 }).notNull(),
emailVerified: timestamp('emailVerified', {
mode: 'date',
}).default(sql`CURRENT_TIMESTAMP`),
image: varchar('image', { length: 255 }),
credits: integer('credits').default(0),
});
export const users = createTable('user', {
id: varchar('id', { length: 255 }).notNull().primaryKey(),
name: varchar('name', { length: 255 }),
email: varchar('email', { length: 255 }).notNull(),
emailVerified: timestamp('emailVerified', {
mode: 'date',
}).default(sql`CURRENT_TIMESTAMP`),
image: varchar('image', { length: 255 }),
credits: integer('credits').default(0),
});
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server