Only has children .write rule [Firebase] -
given following rule:
{ "rules": { "users": { "$uid": { "name":{ ".read": "auth != null && auth.uid == $uid", ".write": "auth != null && auth.uid == $uid" } } } } }
is there way in firebase limit children can written object?
for example limit client writing object 1 attribute:
name { "value": "value" }
i know there .validate
, haschildren()
doesn't prevent user legally write object under $uid undesired attributes.
nothing preventing client writing object follows:
name { "value":"value", "unwantedattribute":"wastingspace" }
is there equivalent hasthosechildrenonly()
?
a .write
rule determines who can write data location, not what data can write.
to determine structure of data written, you'll need .validate
rule. in case can name
required , must string with:
{ ".validate": "newdata.haschild('name')", "name": { ".validate": "newdata.isstring()" }, "$other": { ".validate": false } }
the validate on top-level ensures new data must have name
property. without this, can delete name
, because deleting data not trigger validation.
the second validate ensures name
string.
the third validation ensures child name
rejected.
Comments
Post a Comment