Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase: Get DisplayName from UID [duplicate]

I am storing user's display name in Firebase Auth. Fetching from Firebase Auth is simple when the same user is logged in. But, when another user is logged in, how do I fetch an account's display name when I have their unique UID (User ID).

like image 288
theBrainyGeek Avatar asked Feb 10 '17 06:02

theBrainyGeek


2 Answers

One solution is when you register a user add his details in database also

Example Once you are under createUserWithEmailandPassword()

DatabaseReference db=FirebaseDatabase.getInstance().getReference();
DatabaseReference users = db.child("Users").child(mAuth.getCurrentUser().getUid());
users.child("Name").setValue("<NAME>"); 

Now when the user signs into your database retrieve the Name from the database from child Users

like image 161
Dwijraj Bhattacharyya Avatar answered Sep 30 '22 05:09

Dwijraj Bhattacharyya


You can't get the name, or any other details of a user that is not currently signed in using FirebaseAuth.

Instead, you must create a node in your database where you store the name, and any other necessary details by querying the database.

I'm really curious to know how you have the UID of any other user without doing this.

like image 33
Rohit Navarathna Avatar answered Sep 30 '22 05:09

Rohit Navarathna