Firestore使用.hasAny()规则限制字段

时间:2019-12-17 00:59:36

标签: firebase google-cloud-firestore firebase-authentication firebase-security

我们在Firestore中遇到规则问题。我们要限制写入,以便如果写入某个字段,那么写入将被拒绝。

match /users/{email} {
  allow read: if true;
  allow write: if !isWritingProtectedUserField();
}

function isWritingProtectedUserField() {
  return request.resource.data.keys().hasAny(['restricted']);
  // should allow a write when data is {"something": "val"}
  // should deny a write when data is {"restricted": "val"}
}

此规则在规则模拟器中按预期工作。但是,当尝试写入实际数据时,该规则每次都会给出permission-denied

谢谢。

0 个答案:

没有答案