flutterfire
flutterfire copied to clipboard
[firebase_core]: Using `demoProjectId` doesn't actually connect to demo project
Is there an existing issue for this?
- [X] I have searched the existing issues.
Which plugins are affected?
Cloud Functions, Database, Storage
Which platforms are affected?
Android, iOS
Description
Using the new demoProjectId while initializing firebase app has a weird restriction.
-
If you have already configured firebase using
flutterfire configurethen certain code is added in android and ios directories to usegoogle-services.json&GoogleService-Info.plistas firebase config. -
You cannot create a firebase project with a project id starting with
demo-, hence you cannot useflutterfire configurewith a demo project (as it doesn't exist). -
Hence, when you use
demoProjectIdwhile initializing firebase, there aregoogle-services.json&GoogleService-Info.plistfiles with an actual project config instead of a demo ones. If you remove those files, you'll get errors like:> File google-services.json is missing. The Google Services Plugin cannot function without it.Error (Xcode): Build input file cannot be found: '/Users/user/flutter_app/ios/Runner/GoogleService-Info.plist'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? -
So when using
demoProjectIdwith actual project config ingoogle-services.json&GoogleService-Info.plist, services like Cloud Functions, Firestore, Realtime DB & Storage fails as they try to use the actual config. -
These are the issue with above mentioned services:
- Cloud Functions: Using
httpsCallablewill use the actual project id in the invoked url instead ofdemo-projectId. - Storage: Stores files in a different bucket than default (i.e.
actual-projectId.aappspot.cominstead ofdemo-projectId.aappspot.com) - Firestore: Any operation shows as successful, but NO changes are seen in the Local Firestore Emulator
- Realtime DB: Just like Storage, the data is added into a different instance.
- Cloud Functions: Using
Reproducing the issue
- Run
flutterfire configure -p {{projectId}} --platforms="android,ios"; - Run the Firebase local emulator with
firebase emulators:start --project demo-{{projectId}}; - Set
database.rules,firestore.rules&storage.rulesto allow all operations - Initialize Firebase in Flutter with
Firebase.initializeApp(demoProjectId: 'demo-{{projectId}}'); - Try adding a document in Firestore
- See no doc is actually added in the emulator console UI
- Try uploading image from the flutter app
- See the image is uploaded in the
{{projectId}}.appspot.cominstead ofdemo-{{projectId}}.appspot.combucket.
Firebase Core version
3.1.0
Flutter Version
3.22.2
Relevant Log Output
No response
Flutter dependencies
Expand Flutter dependencies snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
I then tried initializing firebase in flutter with Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); and running local firebase emulator without --project demo-{{projectId}}, and then everything works as expected.
So the issue is most probably with the demoProjectId initialization in flutter.
Also any updates in the firestore.rules and storage.rules files are not reflected when running with --project demo-{{projectId}}.