【问题标题】:Firestore Security Rule allowing unauthenticated access only to one collectionFirestore 安全规则仅允许未经身份验证的访问一个集合
【发布时间】:2017-10-13 17:42:15
【问题描述】:

我正在尝试借助 Firestore 规则建立以下场景。

我怎样才能让用户在没有身份验证的情况下访问“产品”集合,但访问其他经过身份验证的集合?我试过把规则设置如下,但它不起作用。

service cloud.firestore {
  match /databases/{database}/documents {
    // All should be able to access products collection
    match /products {
        allow read;
    }
    // All other collection should only be accessed if user is authenticated.
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

【问题讨论】:

  • 我觉得你需要match /products/{document=**}
  • 如果公共收藏是 /shops/{shopId}/products 怎么办
  • 那你可能需要/shops/{shopId}/products/{document=**}
  • @MichaelBleigh,它奏效了。谢谢。

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


【解决方案1】:

这样的事情会起作用:

service cloud.firestore {
  match /databases/{database}/documents {
    // All should be able to access products collection
    match /products/{allProducts=**} {
        allow read;
    }
    // All other collection should only be accessed if user is authenticated.
    match /{notProducts}/{allNotProducts=**} {
      allow read: if notProducts != "products"
                  && request.auth != null;
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-01
    • 2021-05-13
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    相关资源
    最近更新 更多