generate 2fa backup codes

This commit is contained in:
Milo Schwartz
2024-10-05 15:31:28 -04:00
parent e7080c4aa8
commit 4a5e0e1c57
4 changed files with 40 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ import { fromError } from "zod-validation-error";
import { unauthorized } from "@server/auth";
import { z } from "zod";
import { db } from "@server/db";
import { User, users } from "@server/db/schema";
import { twoFactorBackupCodes, User, users } from "@server/db/schema";
import { eq } from "drizzle-orm";
import { response } from "@server/utils";
import { verifyPassword } from "./password";
@@ -82,6 +82,10 @@ export async function disable2fa(
.set({ twoFactorEnabled: false })
.where(eq(users.id, user.id));
await db
.delete(twoFactorBackupCodes)
.where(eq(twoFactorBackupCodes.userId, user.id));
return response<null>(res, {
data: null,
success: true,