2017-10-13 32 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; 
    } 
    } 
} 
相关问题