CONTEXT
I am currently working on a Firebase application (in Android). I have set up authentication, storage and the database with no issues to speak of. As the Firebase auth user only has a few properties, I have created a "user" POJO to store additional user information that is not contained inside of the Firebase auth user (ie first name, date of birth, nationality, etc...). The structure of this is shown in the image below:
The UUID in the image is the users respective auth uid. This was achieved as such:
ref.child(users).child(auth.getUid()).setValue(user);
This approach seems in line with the documentation as it allows me restrict write/read to the account owner using the auth.uid === $uid
rule. Furthermore, all of the properties inside of the tree map to my POJO as expected.
PROBLEM
My one big problem is that I want to store the users uid inside the POJO. As the UID is currently structured as the objects parent, I am not sure how to map it to the user POJO. I could of course store an additional field in the bottom tree level. However, that seems like pointless data redundancy.
QUESTION
What is the best way to map the uid to a respective "user" POJO class. Ideally I'd be able to fetch 10 users to display, and when one is tapped have the app load a profile activity. This would mean passing the uid of the user, so I can say:
ref.child(users).child(targetUID)
and fetch the tapped user account. This means having their uid.