0
votes

I have read up on Firebase database documentation and I am understanding the basics. But what if I want each user to have their own "list?"

So each user loads up their own list and edits, basically CRUD's their own list? I have created the authentication already, but I am not sure how to proceed here?

2

2 Answers

2
votes

So you'd store the data for each user under their own user id (uid):

userdata
    <uid>
        data1: value1
        data2: value2

Now each user can read their own data with:

var currentUser = firebase.auth().currentUser;
var ref = firebase.database().ref('userdata').child(currentUser.uid);
ref.on('value', function(snapshot) {
  console.log(snapshot.val());
});

That's JavaScript syntax btw. Translate it to Android with the help of the Android guide: https://firebase.google.com/docs/database/android/start/

And then you secure access to that data with these rules:

{
  "rules": {
    "userdata": {
      "$uid": {
        ".read": "auth.uid == $uid",
        ".write": "auth.uid == $uid"
      }
    }
  }
}
0
votes

Add a field with username/id to each record and you filter by that field