feat: improve account security
Support TOTP 2fa, allow for changing password, add session management and account removal.
This commit is contained in:
@@ -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",
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user