Skip to content Skip to sidebar Skip to footer

Authenticated Users Accessing Their Data Using Firebase For Android

I am struggling to make a tie between my users in Firebase, and data that I want it to be linked to. At the moment I am able to create users and log in with users credentials. Ad

Solution 1:

A basic approach that u can take is have a User Id for every maintenance node that you push.

So as per your firebase database you have a user ID "bfPG...." This id can be the parent node for every maintenance record.

If you change this line to this

String id = databaseMaintenance.push().getKey();

this

Stringid= FirebaseAuth.getInstance().getCurrentUser().getUID(); //Check Syntax

you'll be pushing a maintenance record under a user ID and you can then differentiate maintenance records with different users.

Thus in order to get the records for a specific user you have to change your firebase query.

databaseMaintenance = FirebaseDatabase.getInstance().getReference("maintenance").orderByKey().equalTo(id); 

https://firebase.google.com/docs/database/android/lists-of-data

check the link about how to filter records.


Another approach is you have an adapter to which you are adding maintenance records so before you add a record you can check if it belongs to the current user or not and add records accordingly.

Post a Comment for "Authenticated Users Accessing Their Data Using Firebase For Android"