Home > other >  How can i change the error message in Firebase? For example, when invalid password is entered?
How can i change the error message in Firebase? For example, when invalid password is entered?

Time:02-17

Error Message

How can i change the error message? I would like to find a way to customise this error message

This is my sign in method

signInWithEmailAndPassword(auth, email, password)
  .then((res) => {
    dispatch({ type: “LOGIN”, payload: res.user });
    setIsPending(false);
  })
  .catch((err) => {
    setError(err.message);
  });

CodePudding user response:

There is no way to change the error message that Firebase returns, but you can check the error code and then show you own message based on that.

signInWithEmailAndPassword(auth, email, password)
  .then((res) => {
    dispatch({ type: “LOGIN”, payload: res.user });
  })
  .catch((err) => {
    if (err.code === "auth/") {
      setError("The password you entered does not match to this user.");
    }
    else {
      setError(err.message);
    }
  })
  .finally(() => {
    setIsPending(false);
  });

See the full list of error codes to learn what you might want to handle.

  • Related