【问题标题】:Firestore PERMISSION_DENIEDFirestore PERMISSION_DENIED
【发布时间】:2022-01-12 17:24:13
【问题描述】:

当我编写我的颤振应用程序时,我在 macOS 上遇到了这个问题, 相同的基本代码在我的 windows pc 中工作,但在 macOS 中它不起作用。 正如您在我的日志中看到的,应用程序已连接,但我仍然无法在我的 Firestore 数据库上发出请求

我改变了规则

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

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

但我有同样的错误。

D/FirebaseAuth(11790): Notifying id token listeners about user ( tNGS8j375AYehEPDhZADPP80zLY2 ).
W/DynamiteModule(11790): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(11790): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(11790): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/Firestore(11790): (24.0.0) [Firestore]: Listen for Query(target=Query(usersProDEV where uuid == tNGS8j375AYehEPDhZADPP80zLY2 order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter (11790): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

相同的代码在我的 Windows PC 中工作

【问题讨论】:

标签: flutter macos google-cloud-firestore firebase-security apple-m1


【解决方案1】:

projectFolder/android/app/src/main/AndroidManifest.xml 内添加以下内容:

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

【讨论】:

  • 谢谢你,但我添加了但它并没有改变错误
【解决方案2】:

根据post,您的应用程序访问互联网时出现错误。请检查您的网络连接:

检查您在 androidManifest 文件中是否拥有适当的互联网权限(由 Abhishek Dutt 建议)。

如果您使用的是模拟器,请检查模拟器是否可以access the internet使用此帖子。

第一版:

您能否尝试此documentation 中的示例代码进行身份验证:

  service cloud.firestore {
      match /databases/{database}/documents {
        match /messages/{document=**} {
          allow read, update, delete: if request.auth.uid == resource.data.uid;
          allow create: if request.auth.uid != null;
        }
      }
    }

此代码必须仅适用于读取而不是写入:

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

【讨论】:

  • 感谢您的回复,同时,通过 otp 验证建立连接,在我输入验证码并收到您在控制台中看到但通过 firestore 获取数据的令牌是否存在问题。
  • 在我的答案中添加了一些代码,你能试试吗
【解决方案3】:

几次之后,我意识到问题不仅在 MacO 下,而且在模拟器上。通过进一步挖掘,我意识到我在项目上激活的 AppCheck 不接受模拟器下的调试模式的所有请求。

【讨论】:

    猜你喜欢
    • 2018-09-29
    • 1970-01-01
    • 2022-12-28
    • 2019-02-27
    • 2021-08-06
    • 2021-03-20
    • 2019-01-06
    • 2020-08-14
    • 2019-12-15
    相关资源
    最近更新 更多