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

Changing User Email and Password with Swift and 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 中的所有信息。 电子邮件、密码、姓名等

当我点击完成按钮时,所有信息都更新了,除了电子邮件和密码! 据说处理请求时出错: as the picture here

不知道哪里出错了!我是否以错误的方式使用了 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"]as?NSString as?String

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