我想在上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]。房产时间未定的对象。
应该不会每个请求有time
或TimeStamp
连接到它?这是与我如何初始化我的云功能或客户端应用程序?
下面的截图:
编辑
一种用于更新安全规则,其余片段是:
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
用户可以更新)。
这可能不是你特别情况下是有用的,但是检查令牌对象上的自定义要求,当我有同样的错误。
访问现场之前,你可以使用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;