I have two API calls in onVerificationCodeSubmit that covering reset password logic. The problem is that newPasswordMutation executes before setRestorePasswordToken(data.restoreToken) in verifyCodeMutation success callback.
How can I wait for it?
Any way I can handle it via React-Query tools?
const { mutateAsync: verifyCodeMutation } = useMutation(verifyCode, {
onSuccess: ({ data }) => setRestorePasswordToken(data.restoreToken),
});
const { mutateAsync: newPasswordMutation } = useMutation(createNewPassword, {
enabled: restorePasswordToken,
onSuccess: () => setPasswordResetSuccessfull(true),
});
const onRestorePasswordSubmit = ({ email }) => {
restorePasswordMutation(email);
};
const onVerificationCodeSubmit = async ({ verificationCode, password }) => {
await verifyCodeMutation({ verificationCode, restoreToken });
newPasswordMutation({ password, restorePasswordToken });
};