0

Im currently using Firebase to manage my user. I like the idea that i can store my user infos such as email, photoUrl and others into

let user = FIRAuth.auth()?.currentUser

user?.updateEmail("user@example.com") { error in
  if let error = error {
    // An error happened.
  } else {
    // Email upenter code heredated.
  }
}

now of course this only work for the current sign in user, if i want to retrieve the same info of another user by using another user id how can I retrieve this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
SwiftER
  • 1,235
  • 4
  • 17
  • 40
  • 1
    There is no built-in API to look up a user's information by their UID. Most developers keep a list of user information in another data source (such as the Firebase Database) for that reason. See http://stackoverflow.com/questions/28735377/where-does-firebase-save-its-simple-login-users – Frank van Puffelen Aug 30 '16 at 16:26

1 Answers1

1

You could create a "users" child in your Database's JSON tree and separate each user by their user ID that you can get with FIRAuth.auth()?.currentUser.uid.

So your JSON tree would look something like this:

"root"
    "users"
        "userID12345"
            "email"
            "photoURL"

Then you can pull that data from Firebase in your app by calling:

FIRDatabase.database().reference().child("users").observeEventType(.Value, withBlock: { (snapshot) in
//store the snapshot.value in a dictionary and read your data from there
})
alexisSchreier
  • 677
  • 1
  • 5
  • 21