From d77ba4f7b55dd8bf305149fe4a32d22f1284cc02 Mon Sep 17 00:00:00 2001 From: "Rudy B." Date: Sat, 25 Apr 2026 11:55:23 +0200 Subject: [PATCH] refactor(2FA): use `onSuccess` and `onError` instead of `.then().catch()` --- src/components/modals/TwoFactorSetupModal.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/modals/TwoFactorSetupModal.tsx b/src/components/modals/TwoFactorSetupModal.tsx index 85e9b9512..7daf6be94 100644 --- a/src/components/modals/TwoFactorSetupModal.tsx +++ b/src/components/modals/TwoFactorSetupModal.tsx @@ -64,23 +64,23 @@ export function TwoFactorSetupModal({ required, onClose }: TwoFactorSetupModalPr const [backupCodes, setBackupCodes] = useState(null); const queryClient = useQueryClient(); - const { mutateAsync: initiate } = useUpdateQuery('/2fa/setup/initiate'); + const { mutate: initiate } = useUpdateQuery('/2fa/setup/initiate'); const { mutateAsync: confirm, isPending: isConfirming } = useUpdateQuery('/2fa/setup/confirm'); - const { mutateAsync: cancel } = useUpdateQuery('/2fa/setup/cancel'); + const { mutate: cancel } = useUpdateQuery('/2fa/setup/cancel'); useEffect(() => { - initiate({}) - .then((data: any) => { - setQrCodeDataUrl(data.qrCodeDataUrl); - setManualKey(data.manualKey); - }) - .catch(() => setError(t(messages.error))); + initiate( + {}, + { + onSuccess: (data: any) => { + setQrCodeDataUrl(data.qrCodeDataUrl); + setManualKey(data.manualKey); + }, + onError: () => setError(t(messages.error)), + }, + ); }, []); - useEffect(() => { - console.log({ lengthTracked: otpValue.length }); - }, [otpValue.length]); - const handleConfirm = async (value?: string) => { const token = value ?? otpValue; if (token.length !== 6) return; @@ -94,7 +94,7 @@ export function TwoFactorSetupModal({ required, onClose }: TwoFactorSetupModalPr }; const handleCancel = async () => { - await cancel({}).catch(() => {}); + cancel({}); onClose?.(); };