guness
guness

Reputation: 6616

How to access another FirebaseUser`s properties?

Well, I can access current FirebaseUser object as FirebaseAuth.getInstance().getCurrentUser() and then I can call getPhotoUrl() or getDisplayName() methods. The question is given user UUID, how can access another user's object and call these methods?

PS: on android

Upvotes: 0

Views: 349

Answers (2)

AnupamChugh
AnupamChugh

Reputation: 1899

A FirebaseUser has a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in a separate project's user database; those properties can be updated by the user. You cannot add other properties to the FirebaseUser object directly; instead, you can store the additional properties in your Firebase Realtime Database.

    FirebaseAuth mAuth = FirebaseAuth.getInstance();

mAuth.createUserWithEmailAndPassword("[email protected]", "my pass")
    .continueWithTask(new Continuation<AuthResult, Task<Void>> {
        @Override
        public Task<Void> then(Task<AuthResult> task) {
            if (task.isSuccessful()) {
                FirebaseUser user = task.getResult().getUser();
                DatabaseReference firebaseRef = FirebaseDatabase.getInstance().getReference();
                return firebaseRef.child("users").child(user.getUid()).child("phone").setValue("650-253-0000");
            } else {
                // User creation didn't succeed. Look at the task exception
                // to figure out what went wrong
                Log.w(TAG, "signInWithEmail", task.getException());
            }
        }
    });

Upvotes: 1

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

The common way to do this is to store the shareable information about a user in the Firebase Database.

The documentation on firebase.com had a nice example for this. See https://www.firebase.com/docs/android/guide/user-auth.html#section-storing The approach is still the same with the new Firebase changes, although you'll need to massage the code a bit.

I'll add a note that we need to add a sample of this to the new Firebase documentation too.

Upvotes: 0

Related Questions