So I want to write a security rule to disallow writes if a child node is different then it previously was. E.g. imagine a situation where you want a node to only be writable on creation but never thereafter. Given this requirement, the most obvious solution would seem to be to verify that the new data is equal to the old data.
Sadly, this does not work:
".write": "data.child('someNode').val() === newData.child('someNode').val()"
Nor a more sophisticated approach where I try to cast the object to a string:
".write": "!data.exists() || (data.child('someNode').val() + '') === (newData.child('someNode').val() + '')"
Any way this use case can be supported?
Important Note: The value at someNode has to be an object and can't simply be a string or other primitive. In the case of primitives, either of these methods work fine.
Firebase's security rules do not support comparing JSON fragments. You'll have to compare every leaf node in your rules to test for equality.
E.g.
".validate": "
data.child('someNode/username').val() == newData.child('someNode/username').val()
&& data.child('someNode/displayName').val() == newData.child('someNode/displayName').val()"
"
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