XvKnightvX
XvKnightvX

Reputation: 609

Firebase Realtime Database Dynamic Rules

{
"rules": {
"Users": {
  "$user_id": {
    // grants write access to the owner of this user account
    // whose uid must exactly match the key ($user_id)
    ".write": "$user_id === auth.uid"
  }
}
"BUSINESS NAME HERE": {
".write": "root.child('Users').child(auth.uid).child('BUSINESS NAME HERE').child('Permissions').val() === "MODERATOR""
}
}
}

when a user accesses business information they access the child that they need in the key with the businesses name. As entered above how do i apply this to work dynamically with whatever business names they enter (sorry if this is pretty basic im new to firebase rules). Thanks for any help!!!

Upvotes: 0

Views: 1538

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

You use so-called dollar variables to identify the variable part:

{
    "rules": {
        "Users": {
            "$user_id": {
                // grants write access to the owner of this user account
                // whose uid must exactly match the key ($user_id)
                ".write": "$user_id === auth.uid"
            }
        }
        "$businessName": {
            ".write": "root.child('Users').child(auth.uid).child($businessName).child('Permissions').val() === 'MODERATOR'"
        }
    }
}

Upvotes: 1

Related Questions