Skip to content

Commit ce1b505

Browse files
committed
Fix a bug with the demoProjectId arg to Firebase.initializeApp()
If platform specific configuration files exist for the project (i.e. GoogleService-Info.plist for iOS), the default `MethodChannelFirebaseApp` is initialized using the configuration it specifies. This is fine since multiple `FirebaseApp` instances can exist, however when `MethodChannelFirebase.initializeApp()` is called it uses the default app name (`[DEFAULT]`, from the code) if no name is passed as an argument. Since the default app is initialized using the platform specific configuration before `initializeApp()` is called, the user provided options are ignored. The solution is to ensure a non-null app name is passed to `initializeApp()` to avoid conflicts with platform specific configuration files when the user intends to use a "demo-" project for testing. Since we should be providing a distinct app name for the demo app, the allowance for mismatched options between the specified options and the existing options for demo apps is also removed.
1 parent 41890d6 commit ce1b505

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

packages/firebase_core/firebase_core/lib/src/firebase.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Firebase {
5353
platformString = 'web';
5454
}
5555
FirebaseAppPlatform app = await _delegate.initializeApp(
56+
name: name ?? demoProjectId,
5657
options: FirebaseOptions(
5758
apiKey: '',
5859
appId: '1:1:$platformString:1',

packages/firebase_core/firebase_core_platform_interface/lib/src/method_channel/method_channel_firebase.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ class MethodChannelFirebase extends FirebasePlatform {
121121
// check to see if options are roughly identical (so we don't unnecessarily
122122
// throw on minor differences such as platform specific keys missing
123123
// e.g. hot reloads/restarts).
124-
if (defaultApp != null &&
125-
_options != null &&
126-
!_options.projectId.startsWith('demo-')) {
124+
if (defaultApp != null && _options != null &&) {
127125
if (_options.apiKey != defaultApp.options.apiKey ||
128126
(_options.databaseURL != null &&
129127
_options.databaseURL != defaultApp.options.databaseURL) ||

0 commit comments

Comments
 (0)