Reputation: 2503
It is possible to enforce field types with firestore security rules but is it possible to enforce field VALUE?
Lets say when a message is seen by the user.. The message seen
field gets updated to true
. And because this can never go back to false. How do I write a rule to only update seen
field if it is to be updated to true
.
Upvotes: 1
Views: 216
Reputation: 50830
The following rules should:
false
true
only that too it is currently false
match /messages/{messageId} {
allow create: if request.resource.data.seen == false;
allow update: if resource.data.seen == false && request.resource.data.seen == true;
}
Do update the rules as per other requirements e.g. user must be authenticated and so on.
resource.data
contains data of document being updated and request.resource.data
contains data to be added/updated in the document. More details about this can be found in the documentation
Upvotes: 2