TwoFactor plugins requires id column in schema?

I'm getting the following error message, when calling authClient.twoFactor.enable:
# SERVER_ERROR: [BetterAuthError: The field "id" does not exist in the "twoFactor" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".] {
cause: undefined
}
# SERVER_ERROR: [BetterAuthError: The field "id" does not exist in the "twoFactor" schema. Please update your drizzle schema or re-generate using "npx @better-auth/cli generate".] {
cause: undefined
}
AFAIK, the twoFactor table doesn't need an ID column and the documentation doesn't mention one. Config:
database: drizzleAdapter(db, {
provider: 'pg', // or "mysql", "sqlite"
schema: {
user: users,
session: sessions,
account: accounts,
verification: verifications,
twoFactor: twoFactors
}
}),

export const twoFactors = pgTable('twoFactor', {
userId: text()
.primaryKey()
.references(() => users.id, { onDelete: 'cascade' }),
secret: text().notNull(),
backupCodes: text().notNull()
});
database: drizzleAdapter(db, {
provider: 'pg', // or "mysql", "sqlite"
schema: {
user: users,
session: sessions,
account: accounts,
verification: verifications,
twoFactor: twoFactors
}
}),

export const twoFactors = pgTable('twoFactor', {
userId: text()
.primaryKey()
.references(() => users.id, { onDelete: 'cascade' }),
secret: text().notNull(),
backupCodes: text().notNull()
});
Solution:
will be updated
Jump to solution
5 Replies
Jan
JanOP2mo ago
This is my table configuration
No description
Jan
JanOP2mo ago
GitHub
TwoFactor expects id column · Issue #1711 · better-auth/better-auth
Is this suited for github? Yes, this is suited for github To Reproduce Database schema according to documentation: export const twoFactors = pgTable('twoFactor', { userId: text() .primaryKe...
bekacru
bekacru2mo ago
add id field in your schema. follow the schema on the docs
Jan
JanOP2mo ago
Solution
bekacru
bekacru2mo ago
will be updated

Did you find this page helpful?