Skip to content

Commit d77ba4f

Browse files
committed
refactor(2FA): use onSuccess and onError instead of .then().catch()
1 parent 1eb37f2 commit d77ba4f

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/components/modals/TwoFactorSetupModal.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ export function TwoFactorSetupModal({ required, onClose }: TwoFactorSetupModalPr
6464
const [backupCodes, setBackupCodes] = useState<string[] | null>(null);
6565

6666
const queryClient = useQueryClient();
67-
const { mutateAsync: initiate } = useUpdateQuery('/2fa/setup/initiate');
67+
const { mutate: initiate } = useUpdateQuery('/2fa/setup/initiate');
6868
const { mutateAsync: confirm, isPending: isConfirming } = useUpdateQuery('/2fa/setup/confirm');
69-
const { mutateAsync: cancel } = useUpdateQuery('/2fa/setup/cancel');
69+
const { mutate: cancel } = useUpdateQuery('/2fa/setup/cancel');
7070

7171
useEffect(() => {
72-
initiate({})
73-
.then((data: any) => {
74-
setQrCodeDataUrl(data.qrCodeDataUrl);
75-
setManualKey(data.manualKey);
76-
})
77-
.catch(() => setError(t(messages.error)));
72+
initiate(
73+
{},
74+
{
75+
onSuccess: (data: any) => {
76+
setQrCodeDataUrl(data.qrCodeDataUrl);
77+
setManualKey(data.manualKey);
78+
},
79+
onError: () => setError(t(messages.error)),
80+
},
81+
);
7882
}, []);
7983

80-
useEffect(() => {
81-
console.log({ lengthTracked: otpValue.length });
82-
}, [otpValue.length]);
83-
8484
const handleConfirm = async (value?: string) => {
8585
const token = value ?? otpValue;
8686
if (token.length !== 6) return;
@@ -94,7 +94,7 @@ export function TwoFactorSetupModal({ required, onClose }: TwoFactorSetupModalPr
9494
};
9595

9696
const handleCancel = async () => {
97-
await cancel({}).catch(() => {});
97+
cancel({});
9898
onClose?.();
9999
};
100100

0 commit comments

Comments
 (0)