react-firebase-hooks icon indicating copy to clipboard operation
react-firebase-hooks copied to clipboard

CreateUserWithEmailAndPassword doesn't return error for existing users

Open metacoding opened this issue 3 years ago • 0 comments

If there is a user with the same email registered, the call will continue and then() method will be called. There is an HTTP error 400 visible in the console log that is not returned as an error (User Exists)

Example code:

const handleSignup = () => {
    const newUser: CoreUser = {
      email: watch("email"),
      password: watch("password"),
    };
    if (createUserWithEmailAndPassword) {
      createUserWithEmailAndPassword(newUser.email, newUser.password)
        .then((result) => {
          sendEmailVerification()
            .then((result) => {
              console.log(`Email was sent to ${newUser.email} `);
            })
            .catch((error) => {
              console.error(
                `error while sending email: ${error.message}`,
                error
              );
            });
          dispatch(userSignUpSuccess());
        })
        .catch((error) => {
          dispatch(userSignUpError(error));
        });
    }
  };

Console log: CleanShot 2022-03-11 at 06 34 53

Error returned visible in network section:

{
    "error": {
        "code": 400,
        "message": "EMAIL_EXISTS",
        "errors": [
            {
                "message": "EMAIL_EXISTS",
                "domain": "global",
                "reason": "invalid"
            }
        ]
    }
}

metacoding avatar Mar 11 '22 06:03 metacoding