您如何使用 firebase 和 swift 更新用户配置文件设置?

How do you update a users profile settings using firebase and swift?

我正在尝试更新用户的电子邮件和全名。这是我的代码:

func saveTapped() {

    var performSegue = false

    if updateEmail.text == "" && updateFullName.text == "" {
        self.cleanUrCodeRohan("Please fill in one or more of the missing text fields that you would like to update.")
    }

    if updateEmail.text != "" {

        let user = FIRAuth.auth()?.currentUser

        user?.updateEmail(updateEmail.text!) { error in
            self.ref.child("users").child(self.currentUser).child("email").setValue(self.updateEmail.text!)

        }

        let emailUpdateRef = FIRDatabase.database().reference().child(currentUser).child("email")
        print(emailUpdateRef)
        emailUpdateRef.setValue(self.updateEmail.text)

        performSegue = true
    }

    if updateFullName.text != "" {
        let user = FIRAuth.auth()?.currentUser
        if let user = user {
            let changeRequest = user.profileChangeRequest()
            changeRequest.displayName = self.updateFullName.text!
        }
        performSegue = true
    }

    if performSegue == true {
        self.navigationController!.popViewControllerAnimated(true)
    }
}

我可以在授权下更新电子邮件,但不能在数据库下更新。任何帮助将不胜感激。

如果JSON树是这样的:-

 appName{
     users :{
         userID :{
             email : "..",
             username : ".."
         }
     }
 }

使用此代码更新节点的子值:-

func saveTapped(){

if ((updateEmail.text != "" || updateFullName.text != "") && (updateEmail.text != nil || updateFullName.text != nil)){

    let userRef = FIRDatabase.database().reference().child("users").child(FIRAuth.auth()!.currentUser!.uid)
    if let new_Email = updateEmail.text as? String{

        FIRAuth.auth()!.currentUser!.updateEmail(updateEmail.text!) { error in

            if error == nil{
                userRef.updateChildValues(["email" : new_Email ], withCompletionBlock: {(errEM, referenceEM)   in

                    if errEM == nil{
                        print(referenceEM)
                    }else{
                        print(errEM?.localizedDescription)
                    }
                })
            }
        }else{
            self.cleanUrCodeRohan("Email couldn't be updated in auth")
        }
    }

    if let new_Name = updateFullName.text as? String{

        userRef.updateChildValues(["username" : new_Name ], withCompletionBlock: {(errNM, referenceNM)   in

            if errNM == nil{
                print(referenceNM)
            }else{
                print(errNM?.localizedDescription)
            }
        })
    }

}else{

    self.cleanUrCodeRohan("Please fill in one or more of the missing text fields that you would like to update.")

    }
}