Fire Beast

One hidden but handy Firestore security rules feature

If you want to check which fields have updated in Firestore security rules you can use request.writeFields:

match /invitations/{invitationId} {
  allow update: if request.writeFields.hasOnly(['acceptKey', 'state', 'acceptedAt'])
    && request.resource.data.state == 'accepted'
    && request.resource.data.acceptKey == resource.data.key
    && request.resource.data.acceptedAt is request.time

  // Other rules...
}

However, there're a few problems with it!

First of all, it works only for allow update.

Secondly, it includes all fields that were included in the update request, even if the passed values are equal to the current ones.

Because of these two problems Firebase the Firebase team decided to deprecate it and promised to come up with a better solution but as of 31 January 2020, there's still no replacement for it.

Lastly, it doesn't work in the simulator.


So, if you understand its limitations and ready to sacrifice the simulator, feel free to use.