简体   繁体   English

Firebase 规则——无法访问我的收藏

[英]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.

相关问题 我无法访问我的 Firebase Crashlytics 仪表板 - I can't access my Firebase Crashlytics Dashboard 如何在 firebase firestore 设置规则中授予读写权限 - How can give access to read but not write in firebase firestore settting rules Firebase 规则 人人能读,无人能写 - Firebase Rules Everyone reads and no one can write 如何访问 firebase FirebaseError:预期 collection() 的第一个参数是 CollectionReference、DocumentReference 或 FirebaseFirestore - How can I access firebase FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore 为什么我的 Firebase Cloud Function 不能使用“allAuthenticatedUsers”? - Why can't I use `allAuthenticatedUsers` for my Firebase Cloud Function? 使用 Redux 和 React 时无法从 Firebase 集合中删除数据(doc) - Can't delete data (doc) from Firebase collection when using Redux and React 有谁知道,为什么我不能从 firebase 集合中获取所有文档? - Does anyone know, why I can´t get ALL document from a firebase Collection? Flutter firebase 检索我的对话列表集合 - Flutter firebase retrieve My Conversations List collection Firebase 存储访问规则有私有缓存控制 - Firebase storage access rules have private cache control firebase 安全规则只对一个特定字段进行写访问 - firebase security-rules write access to only one specific field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM