feat: Improve MFA check reliability

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 19:06:35 +00:00
parent 47c1a39442
commit 152a90ae9d
3 changed files with 51 additions and 2 deletions

View File

@@ -93,6 +93,17 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { aal } = useAuth(); const { aal } = useAuth();
// Debug AAL status
useEffect(() => {
logger.log('🔐 [QUEUE MANAGER] AAL Status:', {
aal,
isNull: aal === null,
isAal1: aal === 'aal1',
isAal2: aal === 'aal2',
timestamp: new Date().toISOString()
});
}, [aal]);
// Initialize sub-hooks // Initialize sub-hooks
const filters = useModerationFilters({ const filters = useModerationFilters({
initialEntityFilter: "all", initialEntityFilter: "all",
@@ -273,7 +284,30 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
setActionLoading(item.id); setActionLoading(item.id);
// Check MFA (AAL2) requirement before moderation action // Check MFA (AAL2) requirement before moderation action
if (aal === null) {
logger.log('⏳ [QUEUE MANAGER] AAL is null, waiting for authentication status...');
toast({
title: "Loading Authentication Status",
description: "Please wait while we verify your authentication level...",
});
setActionLoading(null);
// Retry after 1 second
setTimeout(() => {
logger.log('🔄 [QUEUE MANAGER] Retrying action after AAL load');
performAction(item, action, moderatorNotes);
}, 1000);
return;
}
if (aal !== 'aal2') { if (aal !== 'aal2') {
logger.warn('🚫 [QUEUE MANAGER] MFA check failed', {
aal,
expected: 'aal2',
userId: user?.id
});
toast({ toast({
title: "MFA Verification Required", title: "MFA Verification Required",
description: "You must complete multi-factor authentication to perform moderation actions.", description: "You must complete multi-factor authentication to perform moderation actions.",
@@ -283,6 +317,8 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
return; return;
} }
logger.log('✅ [QUEUE MANAGER] MFA check passed', { aal });
// Calculate stat delta for optimistic update // Calculate stat delta for optimistic update
const statDelta: Partial<ModerationStats> = {}; const statDelta: Partial<ModerationStats> = {};

View File

@@ -110,6 +110,7 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
const currentAal = await getSessionAal(session); const currentAal = await getSessionAal(session);
setAal(currentAal); setAal(currentAal);
authLog('[Auth] Current AAL:', currentAal); authLog('[Auth] Current AAL:', currentAal);
console.log('🔐 [Auth] AAL SET:', currentAal); // Explicit console log for debugging
} else { } else {
setAal(null); setAal(null);
} }

View File

@@ -19,17 +19,29 @@ import { setStepUpRequired, setAuthMethod, clearAllAuthFlags } from './sessionFl
* Always returns ground truth from server, not cached session data * Always returns ground truth from server, not cached session data
*/ */
export async function getSessionAal(session: Session | null): Promise<AALLevel> { export async function getSessionAal(session: Session | null): Promise<AALLevel> {
if (!session) return 'aal1'; if (!session) {
console.log('🔍 [AuthService] No session, returning aal1');
return 'aal1';
}
try { try {
const { data, error } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel(); const { data, error } = await supabase.auth.mfa.getAuthenticatorAssuranceLevel();
console.log('🔍 [AuthService] getSessionAal result:', {
hasData: !!data,
currentLevel: data?.currentLevel,
nextLevel: data?.nextLevel,
error: error?.message
});
if (error) { if (error) {
console.error('[AuthService] Error getting AAL:', error); console.error('[AuthService] Error getting AAL:', error);
return 'aal1'; return 'aal1';
} }
return (data.currentLevel as AALLevel) || 'aal1'; const level = (data.currentLevel as AALLevel) || 'aal1';
console.log('🔐 [AuthService] Returning AAL:', level);
return level;
} catch (error) { } catch (error) {
console.error('[AuthService] Exception getting AAL:', error); console.error('[AuthService] Exception getting AAL:', error);
return 'aal1'; return 'aal1';