0
votes

This is my firebase json data.

{
    "Users": {
        "MyData": {
            "002ab7bUmab1CgQsw53abB3g1Ab1": { //UID
                "-A3ABlabkflA_ABabABA": { //this is the databaseReference.child(DBHelper.FIREBASE_POSTS).push().getKey();
                    "display": "123",
                    "result": {
                        "format": "1",
                        "id": 1,
                        "numBits": 0,
                        "syncFirebaseId": "-A3ABlqmkflA_AVabABA",
                        "syncStatus": -1,
                        "text": "1234567",
                        "timestamp": 1514496903005
                    }
                },
                "-A2ABlabkf2A_ABabABA": { //this is the databaseReference.child(DBHelper.FIREBASE_POSTS).push().getKey();
                    "display": "123",
                    "result": {
                        "format": "1",
                        "id": 1,
                        "numBits": 0,
                        "syncFirebaseId": "-A3ABlqmkflA_AVabABA",
                        "syncStatus": -1,
                        "text": "1234567",
                        "timestamp": 1514496903005
                    }
                }
            }
        }
    }
}

Rules:

{
  "rules": {
    "Users": {
      "MyData": {
        "$uid": {
          ".read": "auth != null && auth.uid == $uid"
        }
      }
    }
  }
}

But when I simulate, read operation is denied. I want to allow only authenticated user to update data node that is relevant to his/her own. That user should not be able to edit other's data node (UID).

Here is the result of read simulation:

enter image description here

3
Please edit your question to include the read and write simulation that failed. Also please replace the picture of the JSON tree in your question with the actual JSON as text. You can easily get this by clicking the Export JSON link in the overflow menu (⠇) of your Firebase Database console. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. - Frank van Puffelen
Btw: you've spelled users in the JSON, and Users (with a capital U) in the rules. Rules are case sensitive, so the case must match between JSON and rules. - Frank van Puffelen
@FrankvanPuffelen I edited json and I already tried for capital letter but still not able to perform read simulation. Your help would be very helpful to me. - Smeet
Please edit your question to include the read and write simulation that failed. - Frank van Puffelen
You're trying to read the root of your database. Since your rules grant nobody access to the entire database, the read is rejected. If you simulate reading from /Users/MyData/$theUidThatYouStruckOut it will be allowed. - Frank van Puffelen

3 Answers

1
votes

You're trying to read the root of your database. Since your rules grant nobody access to the entire database, the read is rejected. If you simulate reading from /Users/MyData/$theUidThatYouStruckOut it will be allowed.

0
votes

I think auth.uid == $uid" should be auth.uid === $uid". For more information go through this

0
votes

You have change Rules

{
  "rules": {
    "Users": { *** This Line
      "MyData": {
        "$uid": {
          ".read": "auth != null && auth.uid == $uid"
        }
      }
    }
  }
}