fix: complete two_factor schema to full plugin field set

Adds failedVerificationCount and lockedUntil (brute-force tracking
maintained by the two-factor plugin). The adapter rejects any
two-factor endpoint while declared fields are missing from the drizzle
schema; verified was already added in the previous commit.
This commit is contained in:
Leon Tonhäuser committed 2026-08-25 03:27:51 +02:00
1 parent f42f4d5d2d
commit 11cde23cdb
4 files changed
+1971 -4

No files matched your search

+8 -4
View File
@@ -1,4 +1,4 @@
import { boolean, pgEnum, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { boolean, integer, pgEnum, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
export const portalRoles = ["ADMIN", "EDITORIAL"] as const;
export const portalRole = pgEnum("portal_role", portalRoles);
@@ -16,9 +16,10 @@ export const users = pgTable("user", {
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
});
// Better Auth two-factor plugin model ("twoFactor"). `secret` and
// `backupCodes` are stored encrypted by Better Auth (derived from
// BETTER_AUTH_SECRET).
// Better Auth two-factor plugin model ("twoFactor"). Field set mirrors the
// plugin's schema declaration (secret, backupCodes, userId, verified,
// failedVerificationCount, lockedUntil); `secret` and `backupCodes` are
// stored encrypted by Better Auth (derived from BETTER_AUTH_SECRET).
export const twoFactors = pgTable("two_factor", {
id: uuid("id").defaultRandom().primaryKey(),
userId: uuid("user_id")
@@ -30,6 +31,9 @@ export const twoFactors = pgTable("two_factor", {
// Set by Better Auth's verify-totp step; enable returns verified=false until
// the first valid TOTP code confirms possession of the authenticator.
verified: boolean("verified").notNull().default(false),
// Brute-force protection per row, maintained by the plugin.
failedVerificationCount: integer("failed_verification_count").notNull().default(0),
lockedUntil: timestamp("locked_until", { withTimezone: true }),
});
export const accounts = pgTable("account", {