Firestore Security Rules - How can I check that a field is/isn't being modified?

前端 未结 9 623
孤城傲影
孤城傲影 2020-11-29 07:24

For the life of me, I cannot understand why the following is resulting in a false for allowing writes. Assume my users collection is empty to start

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 07:59

    Since reference to writeFields in documentation has disappeared, I had to come up new way to do what we could do with writeFields.

    function isSameProperty(request, resource, key) {
        return request.resource.data[key] == resource.data[key]
    }
    
    match /myCollection/{id} {
        // before version !request.writeFields.hasAny(['property1','property2','property3', 'property4']);
      allow update: isSameProperty(request, resource, 'property1')
        && isSameProperty(request, resource, 'property2')
        && isSameProperty(request, resource, 'property3')
        && isSameProperty(request, resource, 'property4')
      }
    

提交回复
热议问题