How to check if an email address is already in use in Firebase on iOS?

Viewed 10000

I'm using the Firebase Authentication for my iOS App. Now I want to check that the entered email address is available or not. I have found that I have to use createUserWithEmailAndPassword for this. But the issue is I don't want to pass Password. I only want to check using Email. How can I do this?

6 Answers

The following is the structure of the Firebase function you might be looking for (Swift 4):

Auth.auth().fetchProviders(forEmail: emailAddress, completion: {
        (providers, error) in

        if let error = error {
            print(error.localizedDescription)
        } else if let providers = providers {
            print(providers)
        }
    })

If the email address is already registered to a user, you will get a list of the providers that the email address is used for. Otherwise, the list of providers will be empty, and thus the email address is not registered.

the following code is used for the swift5 with updated firebase version. Auth.auth().fetchSignInMethods(forEmail: emailAddress, completion: { (providers, error) in if let error = error { print(error.localizedDescription) } else if let providers = providers { print(providers) } })

Related