-1

im trying to redirect the page after the user is logged in but I cant

i want to redirect it to another page components inside the project so window solution wont work for me

here is my code:

function toggleSignIn(e) {
    e.preventDefault();
    signInWithEmailAndPassword(auth, email, password)
      .then((response) => {
        console.log(response);
      })
      .catch(function(error) {
        var errorCode = error.code;
        var errorMessage = error.message;
        if (errorCode === "auth/wrong-password") {
          alert("Wrong password.");
        } else {
          alert(errorMessage);
        }
        console.log(error);
      });
  }
  <button
                  to="CardsTabs"
                  type="submit"
                  onClick={toggleSignIn}
                >
                  Giriş Yap
                </button>

noting that i cant use Link becasue it wont be working the firebase auth.

how can i achieve it?

i have tried multpile solutions but them seem old

Hazal Kaya
  • 631
  • 2
  • 5
  • 16

1 Answers1

0

If login succeeded - you can use navigate using react-router's useNavigate hook:

const navigate = useNavigate("www.your-url.com");

You can also do the below, but it will cause a browser refresh, meaning that any state data will be lost:

window.location.href = "www.your-url.com";
Elyasaf755
  • 2,239
  • 18
  • 24