0

This block executes when I submit the login form, if all is ok (status 200) it should push the navigation to "/mi-cuenta" page, this works fine in local but no in production, I have no evident bug or error thrown. I'm using auth and middleware to protect specific paths.

handle submit code:

const handleSubmit = async (e) => {
e.preventDefault();
try {
  const response = await axios.post("/api/auth/login", credentials);
  if (response.status === 200) {
    
    /* document.getElementById("logoClick").click(); */
    router.replace("/mi-cuenta");
    handleLogin("popup");
  }
  const response2 = await axios.get("/api/profile");
  if (response2.status === 200) {
    setIsLogged(true);

    const roles = response2.data.roles;
    for (let role of roles) {
      if (role.name === "admin") {
        setIsAdmin(true);
      }
    }
  }
} catch (error) {
  setIsAdmin(false);
  setIsLogged(false);
  setShowAlert(true);

  console.log("Error: ", error);
}

};

LET1S3N
  • 28
  • 7
  • Once it reaches the line `router.replace("mi-cuenta")` does the URL change or it does nothing at all. – Kakiz Aug 03 '23 at 19:51
  • @Kakiz sorry, about that line I forget to say that I was using router.push("/mi-cuenta") then finally try with router.replace("/mi-cuenta") but without any luck. In both cases the url doesn't change at all. – LET1S3N Aug 03 '23 at 19:57

0 Answers0