相关疑难解决方法(0)

找不到函数错误:名称:[get]。在Firestore安全规则模拟中

match /UserProfile {
    match /{uId}{
    allow get: if isUserLoggedIn() && !isUserBlocked(uId);
  }
Run Code Online (Sandbox Code Playgroud)

当我尝试使用上述安全规则从UserProfile / {uId}获取数据时,在Firestore和代码中抛出以下错误,提示权限不足:

Error running simulation — Error: simulator.rules line [199], column [28]. Function not found error: Name: [get].
Run Code Online (Sandbox Code Playgroud)

现在上面两个函数的定义在这里

function isUserLoggedIn(){
    return request.auth != null;
}

function isUserBlocked(uId){
    return (('blocked' in get(/databases/$(database)/documents/UserSettings/$(uId)).data) && (request.auth.uid in get(/databases/$(database)/documents/UserSettings/$(uId)).data.blocked));
}
Run Code Online (Sandbox Code Playgroud)

第一个功能运行得很好,但是第二个功能却不能

它抛出该错误

据我所知,功能还不错

请帮助我在这个问题上浪费了很多时间

我尝试过的

  1. 我在其中一个线程中读到这是一个暂时性问题,但事实并非如此。现在已经超过48小时
  2. 在某处还提到这仅是模拟器中的错误,但是代码可以平稳运行,即使不是这种情况。在代码中,错误是我所期望的权限不足
  3. 我已经正确阅读了文档,所以我的代码可以在其他规则中测试get方法,并且可以正常工作

多数民众赞成在请帮助

firebase google-cloud-firestore firebase-security-rules

6
推荐指数
1
解决办法
716
查看次数

Firestore 安全规则获取功能错误

当用户注册时,应用程序使用为 Firebase 身份验证生成的相同uid将用户保存在 Firestore 中。现在,我试图写一个地方分开收集(没有用户采集)安全规则的读取写入操作被允许仅当请求者有请求者isAdmin字段设置为true。正如您在图像上看到的,即使get()函数中的路径是正确的,我也收到了一个不存在的错误。什么可能导致此错误?

我尝试了路径的许多变体、更改集合、小写所有内容等。我在 Google 中找不到任何关于此的内容,官方文档显示的用法与我使用它的方式相同。

安全规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /user/{user} {
      allow read,write: if true
    }
    match /akarmi/{akarmiId} {
      allow read, write:
      if get(/databases/$(database)/documents/user/$(request.auth.uid)).data.isAdmin == true
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望此代码能够运行并允许或禁止访问,并且不会抛出不存在的错误。

firebase firebase-security firebase-authentication google-cloud-firestore

3
推荐指数
1
解决办法
1943
查看次数

基本的 firestore 安全规则:exists() 工作 - 为什么 get() 不工作?

我正在尝试根据另一个文档验证 firestore 中的读取。

数据结构由 2 个集合组成:“execution”和“test”。

测试集合中只有 1 个文档,其 id 如下:SRJKCxU4HVDBdB3qyfzG,这些值是:

admin true id: "SRJKCxU4HVDBdB3qyfzG" test: 1

我的安全规则如下所示:

service cloud.firestore {
  match /databases/{database}/documents {

    function testFunction(testId) {
      // return exists(/databases/$(database)/documents/test/$(testId));
      return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG";
    }

    match /execution/{exeid} {
      allow read, write: if testFunction("SRJKCxU4HVDBdB3qyfzG");
    }

  }
}
Run Code Online (Sandbox Code Playgroud)

如果我使用return exists(/databases/$(database)/documents/test/$(testId));一切都按预期工作。但无论如何我都无法让这条线工作return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG"

我真的希望我错过了简单而明显的事情?任何帮助都是很常见的。如果需要的话,我还创建了一个演示 firebase 项目和 stackblitz。

谢谢您的帮助。

更新 - 临时解决方案 由于 firestore 安全规则错误,数据属性未填充。这将得到修复。get() 工作的临时解决方案如下:

get(path).data.prop || get(path).prop

firebase firebase-security angularfire2 google-cloud-firestore

1
推荐指数
1
解决办法
6452
查看次数

Firebase firestore规则,仅在文档包含特定值时才读取

我正在通过官方文档学习安全规则,但我无法使其工作.

在我的users文档集合中user有一些地图值,其中一个是role: "guest".角色价值可以"guest" or "superAdmin"

我想要/users只访问role == "superAdmin"

这是我试过的

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
        allow read: if get(/databases/$(database)/documents/users/$(userId)).data.role == "superAdmin";
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

登录时收到错误 superAdmin

错误错误:权限丢失或不足.

我相信我正确地遵循了文档.并在SO中找到了一个类似的问题,其中说明了一些特定于评估查询中嵌套字段的错误.但我没有嵌套查询.我在这做错什么吗?

这是我的火堆外观

在此输入图像描述

请帮忙.

firebase firebase-security google-cloud-firestore

0
推荐指数
1
解决办法
1490
查看次数