Implement type safety and JSONB elimination

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 13:29:22 +00:00
parent efc33a7dda
commit d54b8a9ae4
10 changed files with 144 additions and 69 deletions

View File

@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react';
import { supabase } from '@/integrations/supabase/client';
import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp';
@@ -25,11 +26,11 @@ export function MFAChallenge({ factorId, onSuccess, onCancel }: MFAChallengeProp
const { data, error } = await supabase.auth.mfa.challenge({ factorId });
if (error) throw error;
setChallengeId(data.id);
} catch (error: any) {
} catch (error) {
toast({
variant: "destructive",
title: "MFA Challenge Failed",
description: error.message
description: getErrorMessage(error)
});
onCancel();
}
@@ -58,11 +59,11 @@ export function MFAChallenge({ factorId, onSuccess, onCancel }: MFAChallengeProp
});
onSuccess();
}
} catch (error: any) {
} catch (error) {
toast({
variant: "destructive",
title: "Verification Failed",
description: error.message || "Invalid code. Please try again."
description: getErrorMessage(error) || "Invalid code. Please try again."
});
setCode('');
} finally {

View File

@@ -1,6 +1,7 @@
import { useState } from 'react';
import { supabase } from '@/integrations/supabase/client';
import { toast } from 'sonner';
import { getErrorMessage } from '@/lib/errorHandler';
import {
AlertDialog,
AlertDialogAction,
@@ -60,9 +61,9 @@ export function MFARemovalDialog({ open, onOpenChange, factorId, onSuccess }: MF
toast.success('Password verified');
setStep('totp');
} catch (error: any) {
} catch (error) {
console.error('Password verification failed:', error);
toast.error('Invalid password. Please try again.');
toast.error(getErrorMessage(error));
} finally {
setLoading(false);
}
@@ -94,9 +95,9 @@ export function MFARemovalDialog({ open, onOpenChange, factorId, onSuccess }: MF
toast.success('TOTP code verified');
setStep('confirm');
} catch (error: any) {
} catch (error) {
console.error('TOTP verification failed:', error);
toast.error('Invalid code. Please try again.');
toast.error(getErrorMessage(error));
} finally {
setLoading(false);
}
@@ -140,9 +141,9 @@ export function MFARemovalDialog({ open, onOpenChange, factorId, onSuccess }: MF
toast.success('Two-factor authentication has been disabled');
handleClose();
onSuccess();
} catch (error: any) {
} catch (error) {
console.error('MFA removal failed:', error);
toast.error('Failed to disable MFA. Please try again.');
toast.error(getErrorMessage(error));
} finally {
setLoading(false);
}

View File

@@ -5,7 +5,7 @@ import { Label } from '@/components/ui/label';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Badge } from '@/components/ui/badge';
import { handleError, handleSuccess, handleInfo, AppError } from '@/lib/errorHandler';
import { handleError, handleSuccess, handleInfo, AppError, getErrorMessage } from '@/lib/errorHandler';
import { logger } from '@/lib/logger';
import { useAuth } from '@/hooks/useAuth';
import { supabase } from '@/integrations/supabase/client';
@@ -48,11 +48,11 @@ export function TOTPSetup() {
updated_at: factor.updated_at
}));
setFactors(totpFactors);
} catch (error: any) {
} catch (error) {
logger.error('Failed to fetch TOTP factors', {
userId: user?.id,
action: 'fetch_totp_factors',
error: error.message
error: getErrorMessage(error)
});
}
};
@@ -73,15 +73,15 @@ export function TOTPSetup() {
setSecret(data.totp.secret);
setFactorId(data.id);
setEnrolling(true);
} catch (error: any) {
} catch (error) {
logger.error('Failed to start TOTP enrollment', {
userId: user?.id,
action: 'totp_enroll_start',
error: error.message
error: getErrorMessage(error)
});
handleError(
new AppError(
error.message || 'Failed to start TOTP enrollment',
getErrorMessage(error) || 'Failed to start TOTP enrollment',
'TOTP_ENROLL_FAILED'
),
{ action: 'Start TOTP enrollment', userId: user?.id }
@@ -146,17 +146,17 @@ export function TOTPSetup() {
window.location.href = '/auth';
}, 2000);
}
} catch (error: any) {
} catch (error) {
logger.error('TOTP verification failed', {
userId: user?.id,
action: 'totp_verify',
error: error.message,
error: getErrorMessage(error),
factorId
});
handleError(
new AppError(
error.message || 'Invalid verification code. Please try again.',
getErrorMessage(error) || 'Invalid verification code. Please try again.',
'TOTP_VERIFY_FAILED'
),
{ action: 'Verify TOTP code', userId: user?.id, metadata: { factorId } }