0

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

@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, 完成: { (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

        }



    })
}
4

1 回答 1

0

这正是错误所说的,您已经有一个使用该电子邮件的用户。相反,使用该auth.signIn方法并检查当前登录的用户

于 2017-12-30T19:50:35.160 回答