mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 10:11:13 -05:00
Implement type safety and JSONB elimination
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 } }
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import {
|
||||
fetchSubmissionItems,
|
||||
buildDependencyTree,
|
||||
@@ -99,10 +100,10 @@ export function SubmissionReviewManager({
|
||||
.filter(item => item.status === 'pending')
|
||||
.map(item => item.id);
|
||||
setSelectedItemIds(new Set(pendingIds));
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to load submission items',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -138,10 +139,10 @@ export function SubmissionReviewManager({
|
||||
// No conflicts, proceed with approval
|
||||
handleApprove();
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to check dependencies',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -244,11 +245,11 @@ export function SubmissionReviewManager({
|
||||
|
||||
onComplete();
|
||||
onOpenChange(false);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error approving items:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to approve items',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -299,11 +300,11 @@ export function SubmissionReviewManager({
|
||||
|
||||
onComplete();
|
||||
onOpenChange(false);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error rejecting items:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: 'Failed to reject items. Please try again.',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -352,11 +353,11 @@ export function SubmissionReviewManager({
|
||||
|
||||
onComplete();
|
||||
onOpenChange(false);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error escalating submission:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to escalate submission',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -419,11 +420,11 @@ export function SubmissionReviewManager({
|
||||
}
|
||||
|
||||
await loadSubmissionItems();
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
console.error('Error changing item status:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to change item status',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
|
||||
@@ -188,8 +188,11 @@ export function RideCreditsManager({ userId }: RideCreditsManagerProps) {
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Type assertion for complex joined data
|
||||
const newCredit = data as unknown as UserRideCredit;
|
||||
|
||||
// Add to existing array
|
||||
setCredits(prev => [...prev, data as any]);
|
||||
setCredits(prev => [...prev, newCredit]);
|
||||
setIsAddDialogOpen(false);
|
||||
} catch (error) {
|
||||
console.error('Error fetching new credit:', error);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { handleError, handleSuccess, AppError } from '@/lib/errorHandler';
|
||||
import { handleError, handleSuccess, AppError, getErrorMessage } from '@/lib/errorHandler';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { Loader2, Shield, CheckCircle2 } from 'lucide-react';
|
||||
@@ -134,16 +134,19 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
// No MFA, proceed with password update
|
||||
await updatePasswordWithNonce(data.newPassword, generatedNonce);
|
||||
}
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('Password change failed', {
|
||||
userId,
|
||||
action: 'password_change',
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
errorCode: error.code,
|
||||
errorStatus: error.status
|
||||
error: getErrorMessage(error),
|
||||
errorCode: error instanceof Error && 'code' in error ? (error as any).code : undefined,
|
||||
errorStatus: error instanceof Error && 'status' in error ? (error as any).status : undefined
|
||||
});
|
||||
|
||||
if (error.message?.includes('rate limit') || error.status === 429) {
|
||||
const errorMessage = getErrorMessage(error);
|
||||
const errorStatus = error instanceof Error && 'status' in error ? (error as any).status : undefined;
|
||||
|
||||
if (errorMessage?.includes('rate limit') || errorStatus === 429) {
|
||||
handleError(
|
||||
new AppError(
|
||||
'Please wait a few minutes before trying again.',
|
||||
@@ -152,7 +155,7 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
),
|
||||
{ action: 'Change password', userId, metadata: { step: 'authentication' } }
|
||||
);
|
||||
} else if (error.message?.includes('Invalid login credentials')) {
|
||||
} else if (errorMessage?.includes('Invalid login credentials')) {
|
||||
handleError(
|
||||
new AppError(
|
||||
'The password you entered is incorrect.',
|
||||
@@ -217,16 +220,16 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
|
||||
// TOTP verified, now update password
|
||||
await updatePasswordWithNonce(newPassword, nonce);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('MFA verification failed', {
|
||||
userId,
|
||||
action: 'password_change_mfa',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
error: getErrorMessage(error)
|
||||
});
|
||||
|
||||
handleError(
|
||||
new AppError(
|
||||
error.message || 'Invalid authentication code',
|
||||
getErrorMessage(error) || 'Invalid authentication code',
|
||||
'MFA_VERIFICATION_FAILED',
|
||||
'TOTP code verification failed'
|
||||
),
|
||||
@@ -277,7 +280,7 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
logger.error('Failed to send password change notification', {
|
||||
userId: user!.id,
|
||||
action: 'password_change_notification',
|
||||
error: notifError instanceof Error ? notifError.message : String(notifError)
|
||||
error: getErrorMessage(notifError)
|
||||
});
|
||||
// Don't fail the password update if notification fails
|
||||
}
|
||||
@@ -293,7 +296,7 @@ export function PasswordUpdateDialog({ open, onOpenChange, onSuccess }: Password
|
||||
setStep('password');
|
||||
setTotpCode('');
|
||||
}, 2000);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Upload } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
|
||||
interface SimplePhotoUploadProps {
|
||||
onUpload: (imageId: string, imageUrl: string) => Promise<void>;
|
||||
@@ -48,10 +49,10 @@ export function SimplePhotoUpload({ onUpload, disabled, children }: SimplePhotoU
|
||||
title: 'Image uploaded',
|
||||
description: 'Your image has been uploaded successfully'
|
||||
});
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: 'Upload failed',
|
||||
description: error.message || 'Failed to upload image',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive'
|
||||
});
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user