Firebase: Get DisplayName from UID [duplicate]

我是研究僧i 提交于 2019-12-07 23:51:26

问题


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).


回答1:


You can't

The explanation is here How do I return a list of users if I use the Firebase simple username & password authentication

You can instead set the user's uid to users node in your database, I use that node to store other user's information. then you can get the number of childs under that node.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/42153249/firebase-get-displayname-from-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!