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

Cha*_*har 1 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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Mik*_*ald 5

像这样的事情会起作用:

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;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)