0

Basically, I have login api and nested then function is there, my question is how I stop from calling as certain condition, pasting my code:

login(values.email, values.password)
  .then((res) => {
    if (res?.value?.data?.unverified) {
      console.log('>>> in', res, RESEND_VERIFICATION_EMAIL_DIALOG);
    } else getMe(true);
  })
  .then(() => ...)

So, if it comes in the above if I have to stop calling nested then and all code. Any help would be appreciated, thanks in advance :).

Priyen Mehta
  • 1,096
  • 1
  • 5
  • 19

1 Answers1

0

you'd better use .then, .catch

login(values.email, values.password)
.then((res) => {
    if (res?.value?.data?.unverified) {
      console.log('>>> in', res, RESEND_VERIFICATION_EMAIL_DIALOG);
    } else getMe(true);
}).catch(function(e) {
    console.log(e); // "oh, no!"
});

PS: I found a good resource about stopping the promise chain which I hope would help you