We're having trouble with rules in Firestore. We want to restrict writes such that if a certain field is written to, then the write will be denied.
match /users/{email} {
allow read: if true;
allow write: if !isWritingProtectedUserField();
}
function isWritingProtectedUserField() {
return request.resource.data.keys().hasAny(['restricted']);
// should allow a write when data is {"something": "val"}
// should deny a write when data is {"restricted": "val"}
}
This rule works as expected in the rules simulator. However, when attempting to write actual data, the rule gives permission-denied
every time.
Thanks in advance.