【问题标题】:Flutter with Firebase DatabaseError: Permission denied [duplicate]与 Firebase DatabaseError 一起颤动:权限被拒绝 [重复]
【发布时间】:2021-02-21 17:50:15
【问题描述】:

在我的 Flutter 项目中测试 Firebase 时,我一直遇到这些 Permission Denied,但我无法弄清楚。我正在使用电子邮件身份验证,它可以正常工作。但是在其他帖子中阅读了这个错误之后,我尝试在我的安全规则中允许 read , write for all :

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;

但我仍然得到同样的错误:

W/RepoOperation(24227): setValue at /1_testing failed: DatabaseError: Permission denied
W/RepoOperation(24227): setValue at /2_testing failed: DatabaseError: Permission denied
E/flutter (24227): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(-3, Permission denied, , null)

我发送数据的代码是:


    final databaseReference = FirebaseDatabase.instance.reference();
    void createRecord(){
    databaseReference.child("1_testing").set({
    'title': 'It worked once',
    'description': 'blablibla'
    });
    databaseReference.child("2_testing").set({
    'title': 'it worked twice',
    'description': 'blobloblo'
    });

我还重新下载并同步了我的 json 文件 你有什么想法 ?如果答案似乎很明显,这是我第一次尝试这个很抱歉:/

【问题讨论】:

  • 您显示的安全规则适用于 Cloud Firestore,而您显示的代码正在访问实时数据库。虽然这两个数据库都是 Firebase 的一部分,但它们是完全独立的,一个的安全规则不适用于另一个。要修复错误,您必须为实时数据库设置规则。有关如何执行此操作的演练,请参阅stackoverflow.com/a/52129163

标签: firebase flutter firebase-realtime-database firebase-authentication


【解决方案1】:

这些是 Firestore 的规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;

在您的代码中,您使用的是实时数据库。您需要导航到控制台中的实时数据库选项卡并将规则更新为以下内容:

{
  // Allow read/write access to all users under any conditions
  // Warning: **NEVER** use this ruleset in production; it allows
  // anyone to overwrite your entire database.

  "rules": {
    ".read": true
    ".write": true
  }
}    

在此处了解更多信息:

https://firebase.google.com/docs/rules/insecure-rules#database

【讨论】:

  • 谢谢彼得。太奇怪了,我遵循了 medium.com 上的教程“如何在 Flutter 中使用 Firebase”,所以我不明白为什么他们会提供引用实时数据库的代码......无论如何,至少我现在知道在哪里看 :)
  • 教程的链接是什么?
  • 好的,我试试看,谢谢:)
猜你喜欢
  • 2018-03-06
  • 2018-12-12
  • 2019-04-27
  • 2020-02-15
  • 2017-12-26
相关资源
最近更新 更多