公司的FireStore安全规则:request.time“的对象未定义”

问题描述 投票:1回答:1

我想在上request.time为例进行了说明,以创建基于AngularFirebase website安全规则。

我的功能

function isThrottled() {
    return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}

当我试图allow update: if isThrottled() == false

然而,当我尝试用这个规则来更新文档,它不能因为暂时没有对象定义。

错误:simulator.rules线[169],柱[12]。房产时间未定的对象。

应该不会每个请求有timeTimeStamp连接到它?这是与我如何初始化我的云功能或客户端应用程序?

下面的截图:

enter image description here enter image description here

编辑

一种用于更新安全规则,其余片段是:

service cloud.firestore {
  match /databases/{db}/documents {
    match /users/{userId} {
      match /username/{id} {
        allow update: if isSelf(userId)
                      && usernameAvailable(incomingData().username)
                      && incomingData().username is string
                      && incomingData().username.size() <= 25
                      && incomingFields().size() == 1
                      && isThrottled() == false;
      }
    }

    function incomingData() {
      return request.resource.data
    }
    function isThrottled() {
        return request.time < resource.data.lastUpdate + duration.value(1, 'm')
        }
    function incomingFields() {
        return incomingData().keys()
    }
    function isSelf(userId) {
        return userId == currentUser().uid;
    }
    function usernameAvailable(username) {
        return !exists(/databases/$(db)/documents/usernames/$(username));
    }


  }
}

所述username集合是各user文件下一个子集合(所述users根集合中的每个文件username仅呼吁1场username用户可以更新)。

google-cloud-firestore firebase-security-rules
1个回答
4
投票

这可能不是你特别情况下是有用的,但是检查令牌对象上的自定义要求,当我有同样的错误。

访问现场之前,你可以使用in检查是否对象上存在的财产。此代码生成错误如果代理未限定:

allow write: if request.auth != null && request.auth.token.agent == true;

如果代理人没有定义此代码工作正常:

allow write: if request.auth != null && "agent" in request.auth.token && request.auth.token.agent == true;
© www.soinside.com 2019 - 2024. All rights reserved.