Allow update on single field in firestore

后端 未结 6 693
南方客
南方客 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:45

    Since request.resource.data will show the future object after the write - the only way is to check every field using the following:

       function notUpdating(field) {
         return !(field in request.resource.data)
          || resource.data[field] == request.resource.data[field]
       }
    
       allow update: if notUpdating('title') && notUpdating('description')
    

    Make sure you validate that the user doesn't update all of the fields except the field you want him to have access to

提交回复
热议问题