簡體   English   中英

Firestore PERMISSION_DENIED

[英]Firestore PERMISSION_DENIED

當我編寫我的 flutter 應用程序時,我在 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

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

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

根據這篇文章,您的應用程序訪問互聯網時出現錯誤。 請檢查您的網絡連接:

檢查您在 androidManifest 文件中是否具有正確的 Internet 權限(由 Abhishek Dutt 建議)。

如果您使用的是模擬器,請檢查模擬器是否可以使用此帖子訪問互聯網

幾次之后,我意識到問題不僅在 MacOs 下,而且在模擬器上。 通過進一步挖掘,我意識到我在項目上激活的 AppCheck 不接受模擬器下調試模式的所有請求。

如文檔https://firebase.google.com/docs/app-check/flutter/debug-provider中所述

  await FirebaseAppCheck.instance.activate(
    // Set androidProvider to `AndroidProvider.debug`
    androidProvider: AndroidProvider.debug,   );

當 Firebase 嘗試向后端發送請求時,您的應用會將本地調試令牌打印到調試 output。 例如:

D DebugAppCheckProvider: Enter this debug secret into the allow list in
the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678

在此處輸入圖像描述

在 Firebase 控制台的 App Check 部分,從應用程序的溢出菜單中選擇 Manage debug tokens。 然后,注冊您在上一步中登錄的調試令牌。

Firebase 控制台

注冊令牌后,Firebase 后端服務會將其視為有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM