Skip to content

Commit 6f6ec72

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

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/components/modals/TwoFactorSetupModal.tsx

Lines changed: 11 additions & 11 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');
6969
const { mutateAsync: 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;

0 commit comments

Comments
 (0)