firebase firestore规则无法按预期工作,允许阅读:如果请求。auth!= null&& request.auth.uid == userId;";"

发布于 2025-02-02 04:13:08 字数 835 浏览 5 评论 0原文

这是我第一次在Firestore中设置安全规则,我想使其成为经过身份验证的用户只能访问。我正在为我的auth系统使用firebase自定义验证。

Firebase安全规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
     allow write: if false; 
     allow read: if request.auth != null && request.auth.uid == userId; 
     }
  }
}

我的数据库架构是./用户/{userId}/...我只希望用户可以在数据库中访问其特定集合。

write 规则是错误的,因此只有我带有管理特权的后端服务器才能

使用以下规则编写我的客户端代码丢弃错误firebaseError:丢失或不足的权限。尝试时打电话阅读。

如果重要的话,我要制作next.js应用程序,并使用标准Web版本9(模块化)Firestore函数

编辑:我更改了规则,仍然会遇到相同的错误...

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

It's my first time setting up security rules in firestore and I want to make it so authenticated users only have access. I'm using firebase custom auth for my auth system.

Firebase security rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
     allow write: if false; 
     allow read: if request.auth != null && request.auth.uid == userId; 
     }
  }
}

my database schema is ./users/{userId}/... I only want users to have access to their specific collection in the database.

The write rule is false so only my backend server with admin privileges can write

With these rules my client side code is throwing the error FirebaseError: Missing or insufficient permissions. when I try to make a call to read.

If it matters I'm making a next.js app and using the standard Web Version 9 (modular) firestore functions

EDIT: I changed the rules to this, still getting the same error...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文