Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase RealTime Rules

my app have an admin panel, and i would like to set firebase rules so that only admin are allowed to put new products or items in certain firebase.Child

i want the only users from the child("Admins") would be allowed to write into other categories like Work, private, video, so how to make a child from a reference like Admins only be able to access other children ?

this is my current firebase-RealTime Rules.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  {
  "rules": {
    "Admins": {
      ".read": true,
      ".write": false
    },
    "Users": {
        ".read": true,
            ".write": true,
          ".validate": "newData.hasChildren(['name', 'phoneNumber', 'uid'])",
          "name": {".validate": true},
          "phoneNumber": {".validate": true},
          "uid": {".validate": true},
          "$other": {".validate": false}
    },
    "PrivateWork": {
      ".read": "auth.uid != null",
        ".write": false
    },
    "Likes": {
      ".read": "auth.uid != null",
        ".write": "auth.uid != null"
    },
    "Work": {
      ".read": "auth.uid != null",
        ".write": false
    },
    "videos": {
      ".read": "auth.uid != null",
        ".write": false
    }
  }
}

enter image description here

>Solution :

To allow admins global write access, you can add a single top-level rule like this:

{
  "rules": {
    ".write": "root.child('Admins').child(auth.uid).exists()",
    "Admins": {
      ...

Since permission cascades downwards, this will also grant them access on all child nodes.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading