【问题标题】:Firestore security rules passing wildcard variable to pathFirestore 安全规则将通配符变量传递给路径
【发布时间】:2023-04-09 05:04:01
【问题描述】:

我有以下安全规则:

    match /collection1/{doc_id} {
      allow read: if (get(/databases/$(database)/documents/collection2/$(doc_id)).author == 
                  request.auth.uid);
    }

我正在做的是尝试将通配符变量从父路径doc_id 传递到get 方法的路径中。 collection1 中此文档的读取权限取决于另一个集合 collection2 中具有相同 ID 的文档的 author 字段。我不相信我将doc_id 传递为$(doc_id) 的方式是正确的,因为我收到以下错误:Property author is undefined on object

我也尝试过(doc_id)\doc_id,但它们在语法上是错误的。那么如何将通配符变量传递给路径呢?

【问题讨论】:

    标签: google-cloud-firestore firebase-security


    【解决方案1】:

    您在其中缺少data,这是获取文档字段所必需的:

    get(/databases/$(database)/documents/collection2/$(doc_id)).data.author
    

    【讨论】:

    • 啊,get(path) returns rules.firestore.Resource 我忘了data。谢谢弗兰克
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 2018-11-15
    相关资源
    最近更新 更多