I use firebase realtime as database for my app and off course i used rules to secure my data so more node database then more rules and now have a big code inside it
my question is about how to define function to make my rules more readable and make it less code
I would to get like this
"rules": {
function isMerchant(auth){
return "root.child('Merchant').child(auth.token.phone_number).exists()";
}
"UsersMetaData" :{
"HistoryMarketVisit":{
"$visitId":{
".read" : isMerchant(auth),
".write" : isMerchant(auth),
}
},
},
},
i see this answer for same question but is for firestore , but want to achieve it in firebase real time
thanks for help
As Doug also answered, the Firebase Realtime Database security rules don't natively have support for declared functions in there.
What you can do however is use Firebase's Bolt security modeling language and compiler. Bolt does support callable functions, by expanding them in the way you'd otherwise do manually, and has many other nifty features.
Unfortunately, Realtime Database rules don't have support for custom functions like you see in Firestore. You will have to duplicate the logic wherever it's needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With