Override types

I set the image to be notNull().
export const users = pgTable('user', {
id: text('id').primaryKey(),
name: text('name').notNull(),
username: text('username').notNull().unique(),
email: text('email').notNull().unique(),
emailVerified: boolean('email_verified').notNull(),
image: text('image').notNull(),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull()
})
export const users = pgTable('user', {
id: text('id').primaryKey(),
name: text('name').notNull(),
username: text('username').notNull().unique(),
email: text('email').notNull().unique(),
emailVerified: boolean('email_verified').notNull(),
image: text('image').notNull(),
createdAt: timestamp('created_at').notNull(),
updatedAt: timestamp('updated_at').notNull()
})
Types:
export type Session = typeof auth.$Infer.Session
export type User = typeof auth.$Infer.Session.user
export type Session = typeof auth.$Infer.Session
export type User = typeof auth.$Infer.Session.user
But I still got image?: string | null | undefined. How to fix it? I don't want to define the type manually.
No description
2 Replies
bekacru
bekacru4w ago
Bettter Auth core fields types can't be changed but you can do something like this
export type User = typeof auth.$Infer.Session.user & {
image: string
}
export type User = typeof auth.$Infer.Session.user & {
image: string
}
Nelson
NelsonOP4w ago
Thanks 🙏🏻

Did you find this page helpful?