firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.5k stars 3.92k forks source link

[firebase_core]: Using `demoProjectId` doesn't actually connect to demo project #12965

Closed OutdatedGuy closed 2 days ago

OutdatedGuy commented 2 weeks ago

Is there an existing issue for this?

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.

  1. If you have already configured firebase using flutterfire configure then certain code is added in android and ios directories to use google-services.json & GoogleService-Info.plist as firebase config.

  2. You cannot create a firebase project with a project id starting with demo-, hence you cannot use flutterfire configure with a demo project (as it doesn't exist).

  3. Hence, when you use demoProjectId while initializing firebase, there are google-services.json & GoogleService-Info.plist files 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?
  4. So when using demoProjectId with actual project config in google-services.json & GoogleService-Info.plist, services like Cloud Functions, Firestore, Realtime DB & Storage fails as they try to use the actual config.

  5. These are the issue with above mentioned services:

    • Cloud Functions: Using httpsCallable will use the actual project id in the invoked url instead of demo-projectId.
    • Storage: Stores files in a different bucket than default (i.e. actual-projectId.aappspot.com instead of demo-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.

Reproducing the issue

  1. Run flutterfire configure -p {{projectId}} --platforms="android,ios";
  2. Run the Firebase local emulator with firebase emulators:start --project demo-{{projectId}};
  3. Set database.rules, firestore.rules & storage.rules to allow all operations
  4. Initialize Firebase in Flutter with Firebase.initializeApp(demoProjectId: 'demo-{{projectId}}');
  5. Try adding a document in Firestore
  6. See no doc is actually added in the emulator console UI
  7. Try uploading image from the flutter app
  8. See the image is uploaded in the {{projectId}}.appspot.com instead of demo-{{projectId}}.appspot.com bucket.

Firebase Core version

3.1.0

Flutter Version

3.22.2

Relevant Log Output

No response

Flutter dependencies

Expand Flutter dependencies snippet
```yaml 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}}.

Lyokone commented 2 days ago

Hello,

  1. This function is meant to use when you haven't run flutterfire configure since a Demo project is local project that has not been created in the cloud yet
  2. The only way of having a project starting with demo is to run firebase emulators:start --project demo-test locally using the Firebase emulator. You cannot create it in the Cloud.

I think you have misunderstood the purpose of this argument which is to quickly test something using the emulator without having to run through all the setup in the Web interface.