使用Swift和Firebase更改用户电子邮件和密码

这是我使用swift和firebase的iOS应用程序的编辑按钮。

var ref = Firebase(url:"https://·············.firebaseio.com") @IBAction func Done(sender: AnyObject) { ref.changeEmailForUser("users/\(self.ref.authData.uid)/email", password: "users/\(self.ref.authData.uid)/provider", toNewEmail: EmailTextField.text) { (ErrorType) -> Void in if ErrorType != nil { print("There was an error processing the request") } else { print("Email changed successfully") } } ref.changePasswordForUser("users/\(self.ref.authData.uid)/email", fromOld: "users/\(self.ref.authData.uid)/provider", toNew: PasswordTextField.text) { (ErrorType) -> Void in if ErrorType != nil { print("There was an error processing the request") } else { print("Password changed successfully") } } ref.childByAppendingPath("users").childByAppendingPath(self.ref.authData.uid).updateChildValues(["name":self.NameTextField.text!,"about":self.TextView.text!,"Picker":self.PickerVar]) } 

当用户点击完成按钮时,我想更新他在firebase中的所有信息。 电子邮件,密码,姓名等

点击完成按钮后,所有信息都会更新,电子邮件和密码除外! 它表示处理请求时出错: 如图所示

我不知道错误在哪里! 我是否以错误的方式使用changeEmailForUser和changePasswordForUser函数?

这是JSON树:

  { "users" : { "7b595e99-b20d-4961-bcf0-6c46956a0cbe" : { "Picker" : "Student", "about" : "Hey, I'm Here", "email" : "mariah@gmail.com", "name" : "Mariah Khayat", "provider" : "password" }, "7eb23db6-6b56-4225-9306-22ed0b935b52" : { "Picker" : "Teacher", "about" : "Hi", "email" : "mmm@gmail.com", "name" : "Memo", "provider" : "password" } } } 

对Firebase API造成一些混淆。 在我看到API之后https://www.firebase.com/docs/ios/api/#firebase_changeEmailForUserpasswordtoNewEmailwithCompletionBlock有明确说:

在此处输入图像描述

因此,对于更新电子邮件用户,这不是更新配置文件的一部分。 因此,根据以下情况,您可以更改电子邮件地址:

  ref.changeEmailForUser("OldEmailthatYouuserForLogin", password: "correctpassword", toNewEmail: "newEmail", withCompletionBlock: { error in if error != nil { print("There was an error processing the request") // There was an error processing the request } else { print("Email changed successfully") // Email changed successfully } }) // Dont use edited email for the old email and edited password for the password make sure you are using your actually email and password 

玛丽亚,

问题是您输入的电子邮件和密码详细信息。 您正在显示电子邮件和密码的路径,但您应该输入调用它们的内容,例如。 而不是“”users /(self.ref.authData.uid)/ email“你应该将它作为ref.authData.providerData [”email“]提供为?NSString as?String

对于密码,您需要编辑Firebase规则,以便用户可以访问自己的密码。