Search code examples
react-nativefirebase-authentication

Firebase Method to check whether an email is already associated with an account


Desired behavior:

I would like to have a method that verify the email address with firebase to throw some error if the email is used/invalid.

createUserWithEmailAndPassword(email, password) does not seem to do the job as I would only want to create the account if the user passes a phone verification on the second page, but I would like to throw some error before the user navigates to the second page.


Solution

  • if you have a backend that can use the Admin SDK, you can implement your own API to do this by following https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data

    admin
      .auth()
      .getUserByEmail(email)
      .then((userRecord) => {
        // handle case email already used
      })
      .catch((error) => {
        // handle case no user already use this email
        // allow going to second page
      // here can handle error notify to user or keep reference for same.
      });