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

@@ -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;
}
};