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

@@ -0,0 +1,2 @@
ALTER TABLE "two_factor" ADD COLUMN "failed_verification_count" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
ALTER TABLE "two_factor" ADD COLUMN "locked_until" timestamp with time zone;
File diff suppressed because it is too large. Load diff
+7
View File
@@ -85,6 +85,13 @@
"when": 1787620365940, "when": 1787620365940,
"tag": "0011_two-factor-verified", "tag": "0011_two-factor-verified",
"breakpoints": true "breakpoints": true
},
{
"idx": 12,
"version": "7",
"when": 1787621254728,
"tag": "0012_two-factor-plugin-fields",
"breakpoints": true
} }
] ]
} }
+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 portalRoles = ["ADMIN", "EDITORIAL"] as const;
export const portalRole = pgEnum("portal_role", portalRoles); export const portalRole = pgEnum("portal_role", portalRoles);
@@ -16,9 +16,10 @@ export const users = pgTable("user", {
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(), updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
}); });
// Better Auth two-factor plugin model ("twoFactor"). `secret` and // Better Auth two-factor plugin model ("twoFactor"). Field set mirrors the
// `backupCodes` are stored encrypted by Better Auth (derived from // plugin's schema declaration (secret, backupCodes, userId, verified,
// BETTER_AUTH_SECRET). // failedVerificationCount, lockedUntil); `secret` and `backupCodes` are
// stored encrypted by Better Auth (derived from BETTER_AUTH_SECRET).
export const twoFactors = pgTable("two_factor", { export const twoFactors = pgTable("two_factor", {
id: uuid("id").defaultRandom().primaryKey(), id: uuid("id").defaultRandom().primaryKey(),
userId: uuid("user_id") 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 // Set by Better Auth's verify-totp step; enable returns verified=false until
// the first valid TOTP code confirms possession of the authenticator. // the first valid TOTP code confirms possession of the authenticator.
verified: boolean("verified").notNull().default(false), 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", { export const accounts = pgTable("account", {