mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 08:31:15 -05:00
Fix AuthModal MFA enforcement
This commit is contained in:
@@ -126,14 +126,19 @@ export function AuthModal({ open, onOpenChange, defaultTab = 'signin' }: AuthMod
|
|||||||
const postAuthResult = await handlePostAuthFlow(data.session, 'password');
|
const postAuthResult = await handlePostAuthFlow(data.session, 'password');
|
||||||
|
|
||||||
if (postAuthResult.success && postAuthResult.data.shouldRedirect) {
|
if (postAuthResult.success && postAuthResult.data.shouldRedirect) {
|
||||||
// Get the TOTP factor ID
|
// CRITICAL SECURITY FIX: Get factor BEFORE destroying session
|
||||||
const { data: factors } = await supabase.auth.mfa.listFactors();
|
const { data: factors } = await supabase.auth.mfa.listFactors();
|
||||||
const totpFactor = factors?.totp?.find(f => f.status === 'verified');
|
const totpFactor = factors?.totp?.find(f => f.status === 'verified');
|
||||||
|
|
||||||
if (totpFactor) {
|
if (totpFactor) {
|
||||||
|
// IMMEDIATELY DESTROY THE AAL1 SESSION (same as Auth.tsx password flow)
|
||||||
|
console.log('[AuthModal] MFA required - destroying AAL1 session before challenge');
|
||||||
|
await supabase.auth.signOut();
|
||||||
|
|
||||||
|
// At this point, user has NO authenticated session
|
||||||
setMfaFactorId(totpFactor.id);
|
setMfaFactorId(totpFactor.id);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return; // Stay in modal, show MFA challenge
|
return; // User has NO session - MFA modal will show
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user