Firestore安全规则允许仅对一个集合进行未经身份验证的访问

时间:2017-10-13 17:42:15

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

我试图在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;
    }
  }
}

1 个答案:

答案 0 :(得分:0)

这样的事情会起作用:

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;
    }
  }
}