简体   繁体   中英

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!!!

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'"
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM