1
votes

I am trying to login to my user after updating firebase, and after tracing the error, I get the following error:

Error Domain=FIRAuthErrorDomain Code=17007 "The email address is already in use by another account." UserInfo={NSLocalizedDescription=The email address is already in use by another account., error_name=ERROR_EMAIL_ALREADY_IN_USE}

After looking it seems to be a because that firebase user is already in use, I am not sure how to fix this. I believe it is because I never signed out the user before closing app, but not am unable to login as any of my users.

Below is my code:

@IBAction func Login(sender: AnyObject) {
        let email = self._Email.text!
        let password = self._Password.text!

        Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
            if error == nil {
                //successfull login
                print("Successful login****************************************")

                //performs a segue to the next view controller
                if user!.isEmailVerified{
                    //if the email is verified
                    let vc = self.storyboard!.instantiateViewController(withIdentifier: "ProfileView") as! ProfileView
                    self.present(vc, animated: true, completion: nil)
                }
                else {
                    print("email is not verified")
                }
            } else {
                print("Some login error")
            }
       }
}
1
You are using createUser for login! This function is meant to be used to register new users not for signing in. Instead use this Auth.auth().signIn(withEmail: email, password: password) - ZassX

1 Answers

1
votes

As ZassX pointed out, you're indeed using the signUp method of the Firebase iOS SDK, which is the createUserWithEmail. Use this method instead to signIn using email and password:

Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
  // ...
}

More info: https://firebase.google.com/docs/auth/ios/password-auth

You can check the list of your registered users in your Firebase Authentication Dashboard (https://console.firebase.google.com)

Also, it is good to print out the error description if you're having an error object. Like so:

print(error.localizedDescription).