Refactor: Complete type safety migration

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 13:22:39 +00:00
parent 3d61d738f2
commit efc33a7dda
10 changed files with 212 additions and 161 deletions

View File

@@ -12,6 +12,7 @@ import { Separator } from '@/components/ui/separator';
import { Zap, Mail, Lock, User, AlertCircle, Eye, EyeOff } from 'lucide-react';
import { supabase } from '@/integrations/supabase/client';
import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { TurnstileCaptcha } from '@/components/auth/TurnstileCaptcha';
import { notificationService } from '@/lib/notificationService';
import { StorageWarning } from '@/components/auth/StorageWarning';
@@ -146,17 +147,18 @@ export default function Auth() {
}
}, 500);
} catch (error: any) {
} catch (error) {
// Reset CAPTCHA widget to force fresh token generation
setSignInCaptchaKey(prev => prev + 1);
console.error('[Auth] Sign in error:', error);
// Enhanced error messages
let errorMessage = error.message;
if (error.message.includes('Invalid login credentials')) {
const errorMsg = getErrorMessage(error);
let errorMessage = errorMsg;
if (errorMsg.includes('Invalid login credentials')) {
errorMessage = 'Invalid email or password. Please try again.';
} else if (error.message.includes('Email not confirmed')) {
} else if (errorMsg.includes('Email not confirmed')) {
errorMessage = 'Please confirm your email address before signing in.';
} else if (error.message.includes('Too many requests')) {
errorMessage = 'Too many login attempts. Please wait a few minutes and try again.';
@@ -279,14 +281,14 @@ export default function Auth() {
title: "Welcome to ThrillWiki!",
description: "Please check your email to verify your account."
});
} catch (error: any) {
} catch (error) {
// Reset CAPTCHA widget to force fresh token generation
setCaptchaKey(prev => prev + 1);
toast({
variant: "destructive",
title: "Sign up failed",
description: error.message
description: getErrorMessage(error)
});
} finally {
setLoading(false);
@@ -319,11 +321,11 @@ export default function Auth() {
title: "Magic link sent!",
description: "Check your email for a sign-in link."
});
} catch (error: any) {
} catch (error) {
toast({
variant: "destructive",
title: "Failed to send magic link",
description: error.message
description: getErrorMessage(error)
});
} finally {
setMagicLinkLoading(false);
@@ -345,11 +347,11 @@ export default function Auth() {
}
});
if (error) throw error;
} catch (error: any) {
} catch (error) {
toast({
variant: "destructive",
title: "Social sign in failed",
description: error.message
description: getErrorMessage(error)
});
}
};

View File

@@ -22,6 +22,7 @@ import { User, MapPin, Calendar, Star, Trophy, Settings, Camera, Edit3, Save, X,
import { Profile as ProfileType, ActivityEntry, ReviewActivity, SubmissionActivity, RankingActivity } from '@/types/database';
import { supabase } from '@/integrations/supabase/client';
import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { PhotoUpload } from '@/components/upload/PhotoUpload';
import { profileEditSchema } from '@/lib/validation';
import { LocationDisplay } from '@/components/profile/LocationDisplay';
@@ -109,8 +110,12 @@ export default function Profile() {
coasterCount: coasterCount,
parkCount: parkCount
});
} catch (error: any) {
} catch (error) {
console.error('Error fetching calculated stats:', error);
toast({
variant: 'destructive',
description: getErrorMessage(error),
});
// Set defaults on error
setCalculatedStats({
rideCount: 0,
@@ -269,8 +274,12 @@ export default function Profile() {
.slice(0, 15) as ActivityEntry[];
setRecentActivity(combined);
} catch (error: any) {
} catch (error) {
console.error('Error fetching recent activity:', error);
toast({
variant: 'destructive',
description: getErrorMessage(error),
});
setRecentActivity([]);
} finally {
setActivityLoading(false);
@@ -326,12 +335,12 @@ export default function Profile() {
await fetchCalculatedStats(data.user_id);
await fetchRecentActivity(data.user_id);
}
} catch (error: any) {
} catch (error) {
console.error('Error fetching profile:', error);
toast({
variant: "destructive",
title: "Error loading profile",
description: error.message
description: getErrorMessage(error)
});
} finally {
setLoading(false);
@@ -367,12 +376,12 @@ export default function Profile() {
await fetchCalculatedStats(user.id);
await fetchRecentActivity(user.id);
}
} catch (error: any) {
} catch (error) {
console.error('Error fetching profile:', error);
toast({
variant: "destructive",
title: "Error loading profile",
description: error.message
description: getErrorMessage(error)
});
} finally {
setLoading(false);
@@ -440,11 +449,11 @@ export default function Profile() {
description: "Your profile has been updated successfully."
});
}
} catch (error: any) {
} catch (error) {
toast({
variant: "destructive",
title: "Error updating profile",
description: error.message
description: getErrorMessage(error)
});
}
};
@@ -485,14 +494,14 @@ export default function Profile() {
title: "Avatar updated",
description: "Your profile picture has been updated successfully."
});
} catch (error: any) {
} catch (error) {
// Revert local state on error
setAvatarUrl(profile?.avatar_url || '');
setAvatarImageId(profile?.avatar_image_id || '');
toast({
variant: "destructive",
title: "Error updating avatar",
description: error.message
description: getErrorMessage(error)
});
}
};