UserInfo = {NSLocalizedDescription =该电子邮件地址已被其他帐户使用。,error_name = ERROR_EMAIL_ALREADY_IN_USE}

时间:2017-12-30 17:50:30

标签: swift firebase authentication createuser

嘿伙计们其实我在这里尝试两件事: - 试图创建一个新帐户并尝试打开登录后出现的屏幕,但它显示"电子邮件已存在错误"。

@IBAction func CreateAcccountButton(_ sender:AnyObject){

guard  let eventInterest = textBox.text,let email = EmailTestfield.text, let password = PasswordTestfield.text, let name = UsernameTestfield.text   else {
    print("Form is not valid")
    return
}

Auth.auth()。createUser(withEmail:email,password:password,completion:{(user,error)in

    if let error = error {
        print(error)
        return
    }

    guard let uid = user?.uid else {
        return
    }

    //successfully authenticated user
    let imageName = UUID().uuidString
    let storageRef = Storage.storage().reference().child("profile_images").child("\(imageName).png")

    if let uploadData = UIImagePNGRepresentation(self.Profilepicture.image!) {
        storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in

            if let error = error {
                print(error)
                return
            }
            print (metadata)
           // let downloadURL = metadata?.downloadURL()
          //  print("URL ", downloadURL)

            if let Profilepictureurl = metadata?.downloadURL()?.absoluteString {
            let values =   ["name": name, "email": email,"EventInterest":eventInterest,"Password":password,"Profilepictureurl": Profilepictureurl ]
                let user = User(dictionary: values as [String : AnyObject])
                let customViewController = MessagesController()
                customViewController.setupNavBarWithUser(user)
                customViewController.fetchUserAndSetupNavBarTitle()
            //    customViewController.navigationItem.title = values["name"] as? String
                self.dismiss(animated: true, completion: nil)
                self.registeruserintoDb(uid,values: values as [String : AnyObject])


            }
        })
    }
}
)
}
fileprivate func registeruserintoDb(_ uid: String, values: [String: AnyObject]) {
    let ref = Database.database().reference()
    let usersReference = ref.child("users").child(uid)

    usersReference.updateChildValues(values, withCompletionBlock: { (err, ref) in

        if err != nil {
            print(err!)
            return

        }



    })
}

1 个答案:

答案 0 :(得分:0)

确切地说错误是什么,您已经拥有该电子邮件的用户。相反,请使用auth.signIn method并检查currently signed in users