Allow update on single field in firestore

后端 未结 6 676
南方客
南方客 2020-12-01 19:03

I want to give a user the right to update a document. But ONLY if the user updates one specific field of this document. All other fields shouldn\'t be changed by this user.<

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 19:47

    Since writeFields is deprecated and should not be used, you will have to examine request.resource.data. However, it always contains all of the fields of the written document (it's final state). This means that you will have to compare all of the fields of the written document to the fields of the original document in resource.data in order to make sure that only the ones that changed are the ones that you allow to be changed.

    Currently this requires an explicit check for every field that could possibly be written, which is not fun to implement. The Firebase team is looking into ways of making this sort of rule easier to express by allowing you to diff the data maps of the "before" and "after" documents.

提交回复
热议问题