Skip to content

Commit 416b731

Browse files
committed
Refactor error handling in use-two-factor-auth.ts to use an array for errors instead of an object
1 parent e18dbbe commit 416b731

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

resources/js/hooks/use-two-factor-auth.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export const useTwoFactorAuth = () => {
2828
const [qrCodeSvg, setQrCodeSvg] = useState<string | null>(null);
2929
const [manualSetupKey, setManualSetupKey] = useState<string | null>(null);
3030
const [recoveryCodesList, setRecoveryCodesList] = useState<string[]>([]);
31-
const [errors, setErrors] = useState<{
32-
qrCode?: string;
33-
setupKey?: string;
34-
recoveryCodes?: string;
35-
}>({});
31+
const [errors, setErrors] = useState<string[]>([]);
3632

3733
const hasSetupData = useMemo<boolean>(() => qrCodeSvg !== null && manualSetupKey !== null, [qrCodeSvg, manualSetupKey]);
3834

@@ -42,7 +38,7 @@ export const useTwoFactorAuth = () => {
4238

4339
setQrCodeSvg(svg);
4440
} catch {
45-
setErrors((prev) => ({ ...prev, qrCode: 'Failed to fetch QR code' }));
41+
setErrors((prev) => [...prev, 'Failed to fetch QR code']);
4642
setQrCodeSvg(null);
4743
}
4844
}, []);
@@ -53,13 +49,13 @@ export const useTwoFactorAuth = () => {
5349

5450
setManualSetupKey(key);
5551
} catch {
56-
setErrors((prev) => ({ ...prev, setupKey: 'Failed to fetch a setup key' }));
52+
setErrors((prev) => [...prev, 'Failed to fetch setup key']);
5753
setManualSetupKey(null);
5854
}
5955
}, []);
6056

6157
const clearErrors = useCallback((): void => {
62-
setErrors({});
58+
setErrors([]);
6359
}, []);
6460

6561
const clearSetupData = useCallback((): void => {
@@ -74,7 +70,7 @@ export const useTwoFactorAuth = () => {
7470

7571
setRecoveryCodesList(codes);
7672
} catch {
77-
setErrors((prev) => ({ ...prev, recoveryCodes: 'Failed to fetch recovery codes' }));
73+
setErrors((prev) => [...prev, 'Failed to fetch recovery codes']);
7874
setRecoveryCodesList([]);
7975
}
8076
}, []);

0 commit comments

Comments
 (0)