[英]Firebase rules -- can't access my collection
My firestore rule for a collection in my database looks like this我的数据库中集合的 Firestore 规则如下所示
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /user_data/{accountId}/nfts {
allow read: if request.auth.token.email[0:42].lower() == acountId.lower();
//allow read : if true;
allow write: if false;
}
}
}
In my request, path is defined:在我的请求中,路径被定义为:
path = "/user_data/0x59f5b98d5b5fc01c8ae10238b93618053e62be20/nfts"
This is the correct path of the collection.这才是收藏的正确路径。
The email address of the requested firebase user is请求的 firebase 用户的电子邮件地址是
0x59f5b98d5b5fc01c8ae10238b93618053e62be20@mysite.com
<-- 42 chars before @ ---> 0x59f5b98d5b5fc01c8ae10238b93618053e62be20@mysite.com
<-- @ 之前的 42 个字符 --->
when I attempt a read using:当我尝试阅读时:
let snap = db.collection(path).valueChanges()
let val = await firstValueFrom(snap);
I keep getting permission denied.我一直被拒绝许可。 It seems clear that is some problem with the
allow read
because if change it to allow read: if true;
很明显,
allow read
存在一些问题,因为如果将其更改为allow read: if true;
I get back the all the documents in the collection.我取回了集合中的所有文档。
I can'tseem to determine what is wrong with with the allow read
statement.我似乎无法确定
allow read
语句有什么问题。
You can expand the circle你可以扩大圈子
allow get: if true;
allow list: if request.auth != null;
allow create: if true;
allow update: if true;
allow delete: if false
You can control through the existing sections you have with a request uid or email您可以通过请求 uid 或电子邮件控制您拥有的现有部分
allow get: if request.auth.= null && request.auth.email == resource.data;{"Here use ur doc name example email"};允许获取:if request.auth.= null && request.auth.email == resource.data;{"Here use ur doc name example email"};
request.auth.uid == resource.data.uid Or; request.auth.uid == resource.data.uid 或;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.