2017-10-13 58 views
0

我試圖在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; 
    } 
    } 
} 
+0

我想你需要'匹配/產品/ {文件= **}' –

+0

如果市民收集/店/ {} shopId /產品 –

+0

然後,你可能需要'/ shop/{shopId}/products/{document = **}' –

回答

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; 
    } 
    } 
} 
相關問題