0
      http
        .post("/user/createAccount", data)
        .then((res) => {
          console.log(res.data);
          navigate("/user/login");
        })
        .catch(function (err) {
          toast.error(`${err.response.data.message}`);
        });
  let user = await UserAccount.findOne({
    where: { emailAccount: data.emailAccount },
    where: { phoneNo: data.phoneNo },
  });
  if (user) {
    res.status(400).json({ message: "Email or Phone Number already exists." });
    return;
  }

The error message is not showing on using toast and data is undefined.

I deleted the .data.message and the toast pop up works again, however when .data.message is added back, data is undefined

1
  • does your api return { data: { message: 'error' } } on error? Commented Jun 6, 2023 at 5:15

1 Answer 1

0

I found the error! It seems the code below seems to turn the data into undefined.

instance.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  if (error.response.status === 401 || error.response.status === 403) {
    localStorage.clear();
    window.location="/user/login"
  }
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.