Home > Net >  Firebase with Swift, sendSignInLinkToEmail succeeds with email not registered
Firebase with Swift, sendSignInLinkToEmail succeeds with email not registered

Time:10-04

I'm implementing sign-in via email link and I have it sending the email, but I'm using an email that has not been registered yet. Is there a way to detect if the email is already registered before calling sendSignInLinkToEmail? No error was reported from the call. TIA!

CodePudding user response:

Maybe this function can help you

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

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

So that if the email doesn't exist it'll return an error otherwise you can run the sendSignInLinkToEmail function

CodePudding user response:

Nabil's answer led me to finding the function fetchSignInMethods, which was just the thing I needed. Posted here for anyone else looking for this.

        Auth.auth().fetchSignInMethods(forEmail: email, completion: {
            methods, error in

            if methods == nil {
                self.showAlert(title: "This email is not registered, please create an account")
                return
            }
        })
  • Related