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

@@ -19,17 +19,29 @@ import { setStepUpRequired, setAuthMethod, clearAllAuthFlags } from './sessionFl
* Always returns ground truth from server, not cached session data
*/
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 {
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) {
console.error('[AuthService] Error getting AAL:', error);
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) {
console.error('[AuthService] Exception getting AAL:', error);
return 'aal1';