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

前端 未结 9 610
孤城傲影
孤城傲影 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 08:16

    Found this rule to work quite well:

    function propChanged(key) {
      // Prop changed if key in req but not res, or if key req and res have same value
      return (
        (key in request.resource.data) && !(key in resource.data)
      ) || (
        (key in request.resource.data) && request.resource.data[key] != resource.data[key]
      );
    }
    

提交回复
热议问题