Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase/Android - Load User by UID

I have only found code snippets to load the currently logged in user:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

But what if I need to load another user's data, like the image path and name? I want to load them by their UID.

I could of course save the data myself like this:

-> users
    -> UID
        -> imagePath
        -> name

But I thought there might be a way to use the FirebaserUser class.

I actually think there has to be some way, it's just not written in the docs.

like image 298
Barthy Avatar asked Oct 31 '22 02:10

Barthy


1 Answers

There's no way to do this directly using FirebaseUser class. The old docs of Firebase 1.0 (Before it was acquired by Google) mentioned that exact scenario and the possible solution. The current doc is not completed yet.

The solution was to save the user's data in the Real-time database keeping the uid as the key. So when you need the data of another user, you'll just have to remember their UID and can search for their data (Exactly like how you mentioned in the question description).

I searched the other way to do that without using Real-time database when I started working on my own app, however after finding no other method and reading the old doc, I gave up and used the database way. Trust me it's way easier and flexible to use the database, instead of hacking your way to avoid using it altogether.

like image 66
noob Avatar answered Nov 08 '22 08:11

noob