You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用能否通过单个App Check连接两个App Check强制的Firestore数据库?

问题:Flutter单App Check实例连接两个Firebase项目Firestore的权限异常

我的Flutter应用连接第一个启用App Check的Cloud Firestore数据库完全正常,但给第二个Firestore数据库启用App Check后,即便已经把iOS模拟器的App Check调试令牌添加到第二个项目的调试令牌区域,查询第二个数据库时还是反复报错:

[cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

第一个启用App Check的数据库能正常获取数据。当前使用App Attest验证方式,iOS模拟器为运行iOS 16.2的iPhone 14 Pro。

可复现的Flutter代码示例

Future<void> main() async {
await Firebase.initializeApp(
     name: "Default",
     options: DefaultFirebaseOptions.currentPlatform,
   );

 if (defaultTargetPlatform == TargetPlatform.android) {
   await Firebase.initializeApp(
     //第二个Firebase项目的Android应用信息
       name: 'secondApp',
       options: const FirebaseOptions(
         apiKey: '',
         appId: '',
         messagingSenderId: '',
         projectId: '',
         storageBucket: '',
       ));
 } else if (defaultTargetPlatform == TargetPlatform.iOS) {
   await Firebase.initializeApp(
     //第二个Firebase项目的iOS应用信息
       name: 'secondApp',
       options: const FirebaseOptions(
         apiKey: '',
         appId: '',
         messagingSenderId: '',
         projectId: '',
         storageBucket: '',
       ));
 }

 await FirebaseAppCheck.instance.activate();
}

第二个数据库的Firestore实例代码

final FirebaseFirestore _firestore2 = FirebaseFirestore.instanceFor(app: Firebase.app('secondApp'));

第二个数据库的Firebase安全规则

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /products/{documents=**} {
           allow read;
    }
  }
}

注:第二个数据库未启用App Check时,能正常与其通信。

请问:能否使用单个App Check实例连接Flutter应用中的两个独立Cloud Firestore数据库?

内容的提问来源于stack exchange,提问作者nialljawad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 21:15:11