使用firebase规则解决permission-denied



我有3个Firestore集合,发票,客户端和信息。我编写了以下规则,仅当用户经过身份验证时才允许在Firestore中读写。

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}

我只想将此规则应用于InvoicesClients集合。对于Infos,每个人都应该能够在没有身份验证的情况下从集合中读写。我试着这样改变规则:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
match /databases/{database}/documents {
match /Infos {
allow read, write: if true;
}
}
}

但是当我试图从Infos读取数据而没有经过身份验证时,我仍然得到一个权限拒绝错误。

可以使用以下规则:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /Infos/{infoId} {
allow read, write: if true;
}
match /Invoices/{invoiceId} {
allow read, write: if request.auth != null;
}
match /Clients/{clientId} {
allow read, write: if request.auth != null;
}
}
}

对于InvoicesClients集合,您将能够读取和写入文档的用户只能如果它们是经过认证的,而对于Infos系列,无论是否经过认证,每个人都可以这样做。

最新更新