0
votes

Implement user level data setup using the sample given in this link https://firebase.google.com/docs/database/security/quickstart#sample-rules Want to implement read/write access only at user level keeping read only rule intact on other nodes.

Final Rule written as

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    },
    ".read": "auth != null",
    ".write": "false"
  }
}

Sample database structure

Want to provide read / write access only to users node not others.

Sample JSON Data

{
   "zmjilhwtlo":{
      "MapData":[
         {
            "CaseId":"1",
            "SectionId":"1"
         },
         {
            "CaseId":"2",
            "SectionId":"2"
         }
      ],
      "MapDataRoot":[
         {
            "SrNo":"1",
            "IsFav":"0",
            "ChapterNo":"data",
            "ChapterName":"dad",
            "ActId":"dfd",
            "SectionName":"dfd",
            "Description":"dfd"
         }
      ]
   },
   "hvbxaotcxw":{
      "MapData":[
         {
            "CaseId":"1",
            "SectionId":"1"
         },
         {
            "CaseId":"2",
            "SectionId":"2"
         }
      ],
      "MapDataRoot":[
         {
            "SrNo":"1",
            "IsFav":"0",
            "ChapterNo":"data",
            "ChapterName":"dad",
            "ActId":"dfd",
            "SectionName":"dfd",
            "Description":"dfd"
         }
      ]
   },
   "aundpytdod":{
      "MapData":[
         {
            "CaseId":"1",
            "SectionId":"1"
         },
         {
            "CaseId":"2",
            "SectionId":"2"
         }
      ],
      "MapDataRoot":[
         {
            "SrNo":"1",
            "IsFav":"0",
            "ChapterNo":"data",
            "ChapterName":"dad",
            "ActId":"dfd",
            "SectionName":"dfd",
            "Description":"dfd"
         }
      ]
   },
   "embpkeanaj":{
      "MapData":[
         {
            "CaseId":"1",
            "SectionId":"1"
         },
         {
            "CaseId":"2",
            "SectionId":"2"
         }
      ],
      "MapDataRoot":[
         {
            "SrNo":"1",
            "IsFav":"0",
            "ChapterNo":"data",
            "ChapterName":"dad",
            "ActId":"dfd",
            "SectionName":"dfd",
            "Description":"dfd"
         }
      ]
   },
   "users":{

   }
}

Error screenshots from simulator enter image description here enter image description here enter image description here enter image description here

1
Show us your database structure. - Alex Mamo
@AlexMamo - updated question with database structure - Amod Gokhale
I cannot see in your schema, the users node and the corresponding uid's beheath it. Can you please add a more specific one? - Alex Mamo
users node is at same level of other nodes.. updated question with sample structure - Amod Gokhale
You just write to the path of the UID that you use in the test, so /users/e32bcdf5..... - Frank van Puffelen

1 Answers

1
votes

Since your security rules don't allow anyone to write to /users, the write to /users that you're trying in the emulator is correct rejected. If you want to see if a user can write their own node, you'll want to write to /users/e32bcdf5.... (or whatever their UID is).