[GH-ISSUE #1711] TwoFactor documentation is missing the id column #8880

Closed
opened 2026-04-13 04:07:45 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @JE4GLE on GitHub (Mar 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1711

Current vs. Expected behavior

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
}

AFAIK, the twoFactor table doesn't need an ID column and the documentation doesn't mention one.

To Reproduce

Database schema according to documentation:

export const twoFactors = pgTable('twoFactor', {
    userId: text()
        .primaryKey()
        .references(() => users.id, { onDelete: 'cascade' }),
    secret: text().notNull(),
    backupCodes: text().notNull()
});

What version of Better Auth are you using?

1.2.3

Provide environment information

- Node: 20.10.0
- Vite: 6.2.0
- OS: macOS

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: drizzleAdapter(db, {
        provider: 'pg', // or "mysql", "sqlite"
        schema: {
            user: users,
            session: sessions,
            account: accounts,
            verification: verifications,
            twoFactor: twoFactors
        }
    }),
    plugins: [
		twoFactor()
	],
});

Additional context

Image

Originally created by @JE4GLE on GitHub (Mar 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1711 ### Current vs. Expected behavior 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 } ``` AFAIK, the twoFactor table doesn't need an ID column and the documentation doesn't mention one. ### To Reproduce Database schema according to documentation: ```javascript export const twoFactors = pgTable('twoFactor', { userId: text() .primaryKey() .references(() => users.id, { onDelete: 'cascade' }), secret: text().notNull(), backupCodes: text().notNull() }); ``` ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash - Node: 20.10.0 - Vite: 6.2.0 - OS: macOS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'pg', // or "mysql", "sqlite" schema: { user: users, session: sessions, account: accounts, verification: verifications, twoFactor: twoFactors } }), plugins: [ twoFactor() ], }); ``` ### Additional context ![Image](https://github.com/user-attachments/assets/b98d48c6-e190-4fd1-9bf1-62d23a697b4d)
GiteaMirror added the lockedbug labels 2026-04-13 04:07:45 -05:00
Author
Owner

@JE4GLE commented on GitHub (Mar 6, 2025):

This issue can be used to track the addition of the column to the documentation

<!-- gh-comment-id:2704641008 --> @JE4GLE commented on GitHub (Mar 6, 2025): This issue can be used to track the addition of the column to the documentation
Author
Owner

@mattyx97 commented on GitHub (Mar 8, 2025):

Any update? i have the same problem
@Bekacru

<!-- gh-comment-id:2708216776 --> @mattyx97 commented on GitHub (Mar 8, 2025): Any update? i have the same problem @Bekacru
Author
Owner

@moshetanzer commented on GitHub (Mar 23, 2025):

Hey,

Documentation explicitly mentions it on schema https://www.better-auth.com/docs/plugins/2fa#schema

(Unless this was added to docs recently only 😊)

<!-- gh-comment-id:2746377265 --> @moshetanzer commented on GitHub (Mar 23, 2025): Hey, Documentation explicitly mentions it on schema https://www.better-auth.com/docs/plugins/2fa#schema (Unless this was added to docs recently only 😊)
Author
Owner

@JE4GLE commented on GitHub (Mar 23, 2025):

Hey,

Documentation explicitly mentions it on schema https://www.better-auth.com/docs/plugins/2fa#schema

(Unless this was added to docs recently only 😊)

It was added, but thank you for bringing this issue back to my attention. I closed it ☺️

<!-- gh-comment-id:2746378465 --> @JE4GLE commented on GitHub (Mar 23, 2025): > Hey, > > Documentation explicitly mentions it on schema https://www.better-auth.com/docs/plugins/2fa#schema > > (Unless this was added to docs recently only 😊) It was added, but thank you for bringing this issue back to my attention. I closed it ☺️
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8880