Allow update on single field in firestore

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

    the same answer of "Scott Crossen" with little change, to be more genric

    function isUpdateToOpenField(attr) {
        return request.resource.data.diff(resource.data).affectedKeys().hasOnly([attr]);
    }
    
    allow update: if isUpdateToOpenField('open');

提交回复
热议问题