I'm having a hard time figuring out why firebase is returning the error code 17011 (which according to Firebase documentation is a user not found error), when creating a user with email and password even after deleting all the users in the database and authentication sections of the firebase console. Although the user is created successfully and added to firebase realtime database the error code keeps popping up. Below is a complete error that gets printed out on the console:
Optional(Error Domain=FIRAuthErrorDomain Code=17011 "There is no user record corresponding to this identifier. The user may have been deleted." UserInfo={NSLocalizedDescription=There is no user record corresponding to this identifier. The user may have been deleted., error_name=ERROR_USER_NOT_FOUND})!
The complete class:
import UIKit
import Firebase
class LoginViewController: UIViewController , UITextFieldDelegate {
@IBOutlet weak var emailField: RoundedCornerTextField!
@IBOutlet weak var passwordField: RoundedCornerTextField!
@IBOutlet weak var segmentedControl: UISegmentedControl!
override func viewDidLoad() {
super.viewDidLoad()
emailField.delegate = self
passwordField.delegate = self
}
@IBAction func signupLoginBtnTapped(_ sender: Any) {
if emailField.text != nil && passwordField.text != nil {
if let email = emailField.text, let password = passwordField.text {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in //Sign in
if error == nil {
if let user = user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
} else {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
}
}
print ("Firebase: Success authentication with Firebase.")
self.dismiss(animated: true, completion: nil)
} else {
if let errorCode = AuthErrorCode(rawValue: error!._code){
switch errorCode {
case.wrongPassword:
self.showAlert("You entered an invalid password please try again!")
default:
self.showAlert("Unexpected error \(errorCode.rawValue) please try again!")
print("Creating user error 1 \(error.debugDescription)!")
}
}
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in //creating a user
if error == nil {
if let user = user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
} else {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData, isDriver: true)
}
} else {
if let errorCode = AuthErrorCode(rawValue: error!._code) {
switch errorCode {
case .invalidEmail:
self.showAlert("You entered an invalid email!")
case .userNotFound:
self.showAlert("User not found")
default:
print("Creating user error 2 \(error.debugDescription)!")
self.showAlert("Unexpected error \(errorCode.rawValue) please try again!")
}
}
}
print("Firebase: user created successfully")
self.dismiss(animated: true, completion: nil)
}
})
}
})
}
}
}
}
And block of code that the error occurs:
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
if let user = user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
}
else {
let userData = ["provider": user.providerID]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData, isDriver: true)
}
}
print ("Firebase: Success authentication with Firebase.")
self.dismiss(animated: true, completion: nil)
}
else {
if let errorCode = AuthErrorCode(rawValue: error!._code){
switch errorCode {
case.wrongPassword:
self.showAlert("You entered an invalid password please try again!")
default:
self.showAlert("Unexpected error \(errorCode.rawValue) please try again!")
print("Creating user error \(error.debugDescription)!")
}
}
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
if let user = user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
}
else {
let userData = ["provider": user.providerID]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData, isDriver: true)
}
}
else {
if let errorCode = AuthErrorCode(rawValue: error!._code) {
switch errorCode {
case .invalidEmail:
self.showAlert("You entered an invalid email!")
case .userNotFound:
self.showAlert("User not found")
default:
print("Creating user error \(error.debugDescription)!")
self.showAlert("Unexpected error \(errorCode.rawValue) please try again!")
}
}
}
self.dismiss(animated: true, completion: nil)
}
The error occurs in the Auth.auth().signIn else block below:
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
if let user = user {
if self.segmentedControl.selectedSegmentIndex == 0 {
let userData = ["provider": user.providerID] as [String: Any]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData)
}
else {
let userData = ["provider": user.providerID]
DataService.instance.createFirebaseDBUser(uid: user.uid, userData: userData, isDriver: true)
}
}
else {
if let errorCode = AuthErrorCode(rawValue: error!._code) {
switch errorCode {
case .invalidEmail:
self.showAlert("You entered an invalid email!")
case .userNotFound:
self.showAlert("User not found")
default:
print("Creating user error \(error.debugDescription)!")
self.showAlert("Unexpected error \(errorCode.rawValue) please try again!")
}
}
}
self.dismiss(animated: true, completion: nil)
}
Could anyone provide a solution to resolve?
P.S Yes I imported firebase to the project and pods are up to date also email/password sign in method in the authentication section of firebase console is enabled.
email
andpassword
correct? – 3stud1ant3