Search code examples
androidfirebase-realtime-databasefirebase-security

how to write a firebase Realtime database rule to match root folder child folders name with New Data custom uid


i want go give some user Special permission to write to a folder like (Sp_Adim) if they have a custom UID . to give permission all custom UID saved in a folder in real time data base how can i check this

    "Newdata.child('S_uid').val === root.child(\"$folder\")"

i tried its not working even the folder are inside there Cust_uid/sdsd get denied

    root.child('Cust_uid').child(\"$custom_id\").exists() === 'sdsd'

What am I doing wrong?


Solution

  • It looks like you're putting the wildcard capture variables in quotes, which is not correct.

    If you have a $custom_id variable in your rules tree, you can use that in a specific rule with:

    root.child('Cust_uid').child(custom_id).exists()
    

    If you want to check the value of a node under that root, be sure to call .val to the end of path too. So:

    newdata.child('S_uid').val === root.child($folder).val()
    

    Finally, note that case is important, so it's newData and not NewData.