From d6efa2d39f44d67068757560d08b551c7f84ef69 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:00:22 +0000 Subject: [PATCH] Fix TOTP setup component --- src/components/auth/TOTPSetup.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/auth/TOTPSetup.tsx b/src/components/auth/TOTPSetup.tsx index 567c3654..1ceb16c2 100644 --- a/src/components/auth/TOTPSetup.tsx +++ b/src/components/auth/TOTPSetup.tsx @@ -94,13 +94,21 @@ export function TOTPSetup() { setLoading(true); try { - const { error } = await supabase.auth.mfa.verify({ + // Step 1: Create a challenge first + const { data: challengeData, error: challengeError } = await supabase.auth.mfa.challenge({ + factorId + }); + + if (challengeError) throw challengeError; + + // Step 2: Verify using the challengeId from the challenge response + const { error: verifyError } = await supabase.auth.mfa.verify({ factorId, - challengeId: factorId, // For enrollment, challengeId is the same as factorId + challengeId: challengeData.id, code: verificationCode.trim() }); - if (error) throw error; + if (verifyError) throw verifyError; toast({ title: 'TOTP Enabled',