feat: improve account security

Support TOTP 2fa, allow for changing password, add session management
and account removal.
This commit is contained in:
Zoe
2026-10-08 12:43:22 -05:00
parent ff33e9c573
commit 4bba529ba8
27 changed files with 4874 additions and 468 deletions
+20
View File
@@ -253,6 +253,7 @@ export const users = pgTable("users", {
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").default(false).notNull(),
image: text("image"),
twoFactorEnabled: boolean("two_factor_enabled").default(false),
createdAt: timestamptz("created_at").defaultNow().notNull(),
updatedAt: timestamptz("updated_at")
.defaultNow()
@@ -260,6 +261,25 @@ export const users = pgTable("users", {
.notNull(),
});
export const twoFactors = pgTable(
"two_factors",
{
id: text("id").primaryKey(),
secret: text("secret").notNull(),
backupCodes: text("backup_codes").notNull(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
verified: boolean("verified").default(true),
failedVerificationCount: integer("failed_verification_count").default(0),
lockedUntil: timestamptz("locked_until"),
},
(table) => [
index("two_factors_secret_idx").on(table.secret),
index("two_factors_userId_idx").on(table.userId),
],
);
export const sessions = pgTable(
"sessions",
{