Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve another user's info like email and displayName in Firebase?

I have a users node in Firebase storing each user's information, but excluding displayName andemail`, which is in firebase auth DB.

One day, I realise that I also need user's displayName and email info. For example, in a page created by another user, I want to display that user's displayName and email.

By given that

  1. displayName and email are not stored under the users node,
  2. the user's uniqueId is known

Is it possible to retrieve the user's displayName and email from firebase auth DB (by either normal user or admin)? or what shall I do for users that were already created in firebase?

Thanks, D

like image 377
Xi Xiao Avatar asked Sep 07 '25 02:09

Xi Xiao


1 Answers

With the AdminSDK it is possible like explained here.

In the doc there is examples for every method, but in your case I guess that you searched for this

admin.auth().getUser(uid)
    .then(function(userRecord) {
        // See the UserRecord reference doc for the contents of userRecord.
        console.log("Successfully fetched user data:", userRecord.toJSON());
    })
    .catch(function(error) {
        console.log("Error fetching user data:", error);
    });

You can do things like userRecord.displayName. The full interface is here.

like image 170
creativecreatorormaybenot Avatar answered Sep 10 '25 15:09

creativecreatorormaybenot