From 6677eebe58f2916baa107cc9e71bad1c66205805 Mon Sep 17 00:00:00 2001
From: B SIMAK AHMED <1NZ24CS030@newhorizonindia.edu>
Date: Tue, 22 Sep 2026 22:01:56 +0530
Subject: [PATCH] Fix backup authenticator enrollment AAL2 flow
---
src/components/SecurityTab.tsx | 98 +++-------------------------------
1 file changed, 8 insertions(+), 90 deletions(-)
diff --git a/src/components/SecurityTab.tsx b/src/components/SecurityTab.tsx
index 6edae84..1e7c67f 100644
--- a/src/components/SecurityTab.tsx
+++ b/src/components/SecurityTab.tsx
@@ -15,7 +15,7 @@ import { supabase } from "@/integrations/supabase/client";
import { useAuth } from "@/hooks/use-auth";
import { toast } from "sonner";
-type Step = "idle" | "enable-password" | "enable-qr" | "enable-complete";
+type Step = "idle" | "enable-qr" | "enable-complete";
export function SecurityTab({
requiredSetup = false,
@@ -32,8 +32,6 @@ export function SecurityTab({
const [qrCode, setQrCode] = useState("");
const [secret, setSecret] = useState("");
const [totpCode, setTotpCode] = useState("");
- const [password, setPassword] = useState("");
- const [showPassword, setShowPassword] = useState(false);
const [busy, setBusy] = useState(false);
const [secretCopied, setSecretCopied] = useState(false);
@@ -54,35 +52,21 @@ export function SecurityTab({
const reset = () => {
setStep("idle");
- setPassword("");
setTotpCode("");
setQrCode("");
setSecret("");
setEnrollFactorId("");
- setShowPassword(false);
setSecretCopied(false);
setBusy(false);
};
- const verifyPassword = async (pw: string): Promise => {
- if (!user?.email) return false;
- const { error } = await supabase.auth.signInWithPassword({
- email: user.email,
- password: pw,
- });
- return !error;
- };
-
- const handleEnablePassword = async () => {
- if (!password) {
- toast.error("Enter your password.");
- return;
- }
-
+ const handleStartEnrollment = async () => {
setBusy(true);
- const ok = await verifyPassword(password);
- if (!ok) {
- toast.error("Incorrect password.");
+
+ const { data: assurance, error: assuranceError } =
+ await supabase.auth.mfa.getAuthenticatorAssuranceLevel();
+ if (assuranceError || assurance.currentLevel !== "aal2") {
+ toast.error("Two-step verification is required before adding a backup authenticator.");
setBusy(false);
return;
}
@@ -109,7 +93,6 @@ export function SecurityTab({
setEnrollFactorId(data.id);
setQrCode(data.totp.qr_code);
setSecret(data.totp.secret);
- setPassword("");
setBusy(false);
setStep("enable-qr");
};
@@ -199,7 +182,7 @@ export function SecurityTab({
? "rounded-xl"
: "rounded-xl bg-gradient-to-r from-violet to-electric text-white"
}
- onClick={() => setStep("enable-password")}
+ onClick={() => void handleStartEnrollment()}
>
{mfaCount > 0 ? (
<>
@@ -221,33 +204,6 @@ export function SecurityTab({
- {step === "enable-password" && (
- }
- title={mfaCount > 0 ? "Add Backup Authenticator" : "Verify Your Password"}
- description="Re-enter your current password before creating a new TOTP factor."
- onClose={reset}
- >
- setShowPassword((visible) => !visible)}
- />
-
-
-
-
-
- )}
{step === "enable-qr" && (
void;
- onToggle: () => void;
-}) {
- return (
-
-
-
- onChange(event.target.value)}
- className="rounded-xl pr-10"
- autoComplete="current-password"
- autoFocus
- />
-
-
-
- );
-}