My Flutter App works perfectly when it is connected to my first Cloud Firestore Database (which is App Check enforced).
I managed to connect my App to a second Cloud Firestore Database. However, after enforcing App Check for the second database, despite entering the App Check Debug Token from the iOS simulator into the debug token section of the App Check for the second database, I am repeatedly getting this error upon querying data from the second database:
[cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
Retrieving data from the first app-check enforced database is totally fine.
I'm using App Attest, iOS simulator is running on iOS 16.2 iPhone 14 Pro.
Reproducible code sample, within flutter:
Future<void> main() async {
await Firebase.initializeApp(
name: "Default",
options: DefaultFirebaseOptions.currentPlatform,
);
if (defaultTargetPlatform == TargetPlatform.android) {
await Firebase.initializeApp(
//Android app ID's from firebase console of project 2
name: 'secondApp',
options: const FirebaseOptions(
apiKey: '',
appId: '',
messagingSenderId: '',
projectId: '',
storageBucket: '',
));
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
await Firebase.initializeApp(
//iOS app ID's from firebase console of project 2
name: 'secondApp',
options: const FirebaseOptions(
apiKey: '',
appId: '',
messagingSenderId: '',
projectId: '',
storageBucket: '',
));
}
await FirebaseAppCheck.instance.activate(
);
}
My separate instance that I'm using to communicate to the second app-check enforced database:
final FirebaseFirestore _firestore2 = FirebaseFirestore.instanceFor(app: Firebase.app('secondApp'));
I have left out the relevant details for the initialisation of the second database. As you can see, app check is activated.
Firebase security rules for second app-check enforced database:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /products/{documents=**} {
allow read
}
}
}
When App Check is not enforced for the second database I am able to communicate with the second database.
Is it possible to use a single App Check instance for 2 separate Cloud Firestore databases that a Flutter App connects to?