Edit information in firebase, swift project

2019-12-16 20:10发布

问题:

How Can I Update the user Information in firebase! For Example, his email, password, and name, etc.

What firebase function would I use?

回答1:

That's a pretty vague question with numerous answers but here's the basics.

Assume you have a Firebase structure like this

users
  uid_0
    user_name: "Bill"
    email: "bill@yipee.com"

To change the user name from Bill to Leeeeroy:

var userNameRef = ref.childByAppendingPath("users/uid_0/user_name")
userNameRef.setValue("Leeeeroy")

The above is a small example. You should investigate using .updateChildValues as well.

The Firebase website has a really good guide on writing data, check it out!

Saving Data

If you are looking into modifying the actual Firebase user data, instead of a users node you have created, look into

  • (void)changeEmailForUser:(NSString *)email password:(NSString *)password toNewEmail:(NSString *)newEmail withCompletionBlock:(void ( ^ ) ( NSError *error ))block

here's the simple swift code to change the users Firebase email

myRootRef.changeEmailForUser("bob@thing.com", password: "old_password", toNewEmail: "new_password") { (<#NSError!#>) -> Void in
    print("done!")
}