You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The BETA version of NextAuth uses { session: { user: AdapterUser } & AdapterSession /** Available when {@link AuthConfig.session} is set tostrategy: "database". */ user: AdapterUser }
as session callback parameter, and the AdapterUser is an interface that extends User: export interface AdapterUser extends User { id: string email: string emailVerified: Date | null }
However, when a custom column that is not defined in type is added to the users table (I used drizzle): export const users = pgTable('user', { id: text('id') .primaryKey() .$defaultFn(() => crypto.randomUUID()), name: text('name'), email: text('email').notNull(), emailVerified: timestamp('emailVerified', { mode: 'date' }), image: text('image'), admin: boolean('admin').default(false) // custom column });
the column is not reflected on the callback: callbacks: { session({ session, user }) { return { ...session, user: { ...session.user, admin: user.admin // this always results in undefined } }; } }
The text was updated successfully, but these errors were encountered:
YTG2G3
added
bug
Something isn't working
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
labels
May 19, 2024
Environment
Reproduction URL
https://github.com/YTG2G3/nextauth-demo
Describe the issue
The BETA version of NextAuth uses
{ session: { user: AdapterUser } & AdapterSession /** Available when {@link AuthConfig.session} is set to
strategy: "database". */ user: AdapterUser }
as session callback parameter, and the AdapterUser is an interface that extends User:
export interface AdapterUser extends User { id: string email: string emailVerified: Date | null }
However, when a custom column that is not defined in type is added to the users table (I used drizzle):
export const users = pgTable('user', { id: text('id') .primaryKey() .$defaultFn(() => crypto.randomUUID()), name: text('name'), email: text('email').notNull(), emailVerified: timestamp('emailVerified', { mode: 'date' }), image: text('image'), admin: boolean('admin').default(false) // custom column });
the column is not reflected on the callback:
callbacks: { session({ session, user }) { return { ...session, user: { ...session.user, admin: user.admin // this always results in undefined } }; } }
Thus, Role Based Access Control does not work
How to reproduce
Explained above
Expected behavior
Current version: {
id: 'UUID-UUID-UUID-UUUUUUUID',
name: 'John Doe',
email: 'john@doe.com',
emailVerified: null,
image: null
}
Expected: {
id: 'UUID-UUID-UUID-UUUUUUUID',
name: 'John Doe',
email: 'john@doe.com',
emailVerified: null,
image: null,
admin: true
}
The text was updated successfully, but these errors were encountered: