flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_core_web] Breaking change from 2.0.2 and up for Flutter web

Open Gorter-dev opened this issue 3 years ago • 18 comments

Bug report

Describe the bug Breaking change in Firebase_core_web from version 2.0.2 and up

Steps to reproduce

Somewhere in main.dart:

Firebase.initializeApp(
    name: '',
    options:  FirebaseOptions(
      apiKey: '',
      authDomain: '',
      databaseURL: '',
      projectId: '',
      storageBucket: '',
      messagingSenderId: '',
      appId: '',
      measurementId: '',
    ),
  ); 

(Items are filled in the app obviously)

Start the app and the error will be:

Error: [core/no-options] Firebase: Need to provide options, when not being deployed to hosting via source..
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49                                  throw_
packages/firebase_core_web/src/firebase_core_web.dart 305:7                                                   app
packages/firebase_core/src/firebase.dart 56:41                                                                app
packages/firebase_auth_platform_interface/src/platform_interface/platform_interface_firebase_auth.dart 42:23  get app
packages/firebase_auth_web/firebase_auth_web.dart 119:68                                                      get delegate
packages/firebase_auth_web/firebase_auth_web.dart 93:47                                                       <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                                            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5                                            _async
packages/firebase_auth_web/firebase_auth_web.dart 92:45                                                       <fn>
packages/firebase_core_web/src/firebase_core_web.dart 283:41                                                  <fn>
dart-sdk/lib/internal/iterable.dart 391:20                                                                    moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 748:20                              next
dart-sdk/lib/async/future.dart 520:16                                                                         wait
packages/firebase_core_web/src/firebase_core_web.dart 275:18                                                  initializeApp
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                                            <fn>
dart-sdk/lib/async/zone.dart 1653:54                                                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5                                                                     [_completeWithValue]
dart-sdk/lib/async/future.dart 528:22                                                                         <fn>
dart-sdk/lib/async/zone.dart 1653:54                                                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                                                    handleValue
dart-sdk/lib/async/future_impl.dart 766:44                                                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 795:13                                                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 566:5                                                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 639:7                                                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                                                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15                                           <fn>

Expected behavior

App running like it does with version 2.0.1

Additional context

Looks to me like it's something in this commit: https://github.com/firebase/flutterfire/pull/10028

Gorter-dev avatar Jan 06 '23 13:01 Gorter-dev

Thanks for the report @Gorter-dev I am unable to replicate this using the plugin example and firebase_core_web: ^2.1.0. I used the same below code snippet inside InitializeApp method that you provided and filled it with my local information.

Firebase.initializeApp(
    name: '',
    options:  FirebaseOptions(
      apiKey: '',
      authDomain: '',
      databaseURL: '',
      projectId: '',
      storageBucket: '',
      messagingSenderId: '',
      appId: '',
      measurementId: '',
    ),
  ); 

Running above in web compiled the app properly and then after clicking on initialize default app, it triggered below error which I think is expected:

Error: [core/bad-app-name] Firebase: Illegal App name: '.

I am on latest master channel. Can you provide exact steps to replicate along with flutter doctor -v and pubspec.yaml ? Also please take a look at plugin example and see if using it, you still get same error or not.

darshankawar avatar Jan 09 '23 10:01 darshankawar

I just ran the example in FlutterFire - FirebaseCore/Example. This works just fine!

I narrowed down the issue to the following: Our application works just fine when I remove the name parameter from the initialization call. However when I add this I get the error message from above.

Looks to me like somewhere in firebase_auth_web.dart it defaults to the default app.

Gorter-dev avatar Jan 09 '23 11:01 Gorter-dev

Our application works just fine when I remove the name parameter from the initialization call. However when I add this I get the error message from above.

This looks similar to https://github.com/firebase/flutterfire/issues/9400 which was reported mentioning an error is thrown on web if name is used, but since has been fixed. Please take a look at it and see if it helps in your case.

darshankawar avatar Jan 10 '23 11:01 darshankawar

I just got this error as well. Confirmed, the error won't throw if the named parameter is removed.

bengarrison avatar Jan 18 '23 19:01 bengarrison

@bengarrison Can you provide a minimal code sample that shows the error along with pubspec.yaml ?

darshankawar avatar Jan 24 '23 10:01 darshankawar

I think it has to do with this getInstance call in the commit I mentioned earlier.

Schermafbeelding 2023-01-26 om 09 45 41

The problem itself seems easy enough, when the name parameter is added on the said version. The app won't start because of the feature: currentUser is now populated right at the start of the application without needing to wait for authStateChange, because this works only for the DEFAULT_APP and not any named instance.

EDIT: See posts below

Gorter-dev avatar Jan 26 '23 08:01 Gorter-dev

When I comment out this line: await FirebaseAuthWeb.instance.delegate.onWaitInitState();

The error is gone.

Schermafbeelding 2023-01-26 om 10 28 24

Firebase_auth_web: 5.2.3

After testing, there is something going on with this line. Don't really know what is yet. The contents of the onWaitInitState doesn't seem to matter. (even with an empty function body, the error still comes up).

Gorter-dev avatar Jan 26 '23 09:01 Gorter-dev

I figured the whole thing out:

When using: firebase_auth_web 5.2.3 firebase_core_web: 2.0.2 firebase_auth_platform_interface: 6.11.6

And having a not empty name in the firebase intializeApp function.

This static function get called initially: Schermafbeelding 2023-01-26 om 11 07 00

In this function there is a call to a getter named delegate Schermafbeelding 2023-01-26 om 11 09 16

this delegate uses app, app comes from the firebase_auth_platform_interface Schermafbeelding 2023-01-26 om 11 11 13

This getter of app return the appInstance or Firebase.app()

And due to the moment of calling the first static function the appInstance will always be null. Therefore returning the firebase.app(), whilst the project intializes a named app.

The solution (I think), will something delaying the call FirebaseAuthWeb.instance.delegate.onWaitInitState(); to a later moment after initialization is completed, thus appInstance will not be null.

I don't know what complications this will have for the feature: currentUser is now populated right at the start of the application without needing to wait for authStateChange, this will therefore be also delayed.

Kind regards,

Gorter-dev avatar Jan 26 '23 10:01 Gorter-dev

Thanks for the update and digging in @Gorter-dev

With the details provided above, I was able to replicate the original error described using plugin example.

Screenshot 2023-01-27 at 4 13 03 PM

Added name parameter to initializeApp as below:

Future<void> initializeDefault() async {
    FirebaseApp app = await Firebase.initializeApp(
      name: 'test',
      options: FirebaseOptions(

Upon running the app which compiles properly but then tapping to initialize either the default or secondary app throw below exception:

console error log

Error: [core/no-options] Firebase: Need to provide options, when not being deployed to hosting via source..
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49                                  throw_
packages/firebase_core_web/src/firebase_core_web.dart 305:7                                                   app
packages/firebase_core/src/firebase.dart 56:41                                                                app
packages/firebase_auth_platform_interface/src/platform_interface/platform_interface_firebase_auth.dart 42:23  get app
packages/firebase_auth_web/firebase_auth_web.dart 119:68                                                      get delegate
packages/firebase_auth_web/firebase_auth_web.dart 93:47                                                       <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54                                            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5                                            _async
packages/firebase_auth_web/firebase_auth_web.dart 92:45                                                       <fn>
packages/firebase_core_web/src/firebase_core_web.dart 283:41                                                  <fn>
dart-sdk/lib/internal/iterable.dart 393:20                                                                    moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 831:20                              next
dart-sdk/lib/async/future.dart 520:16                                                                         wait
packages/firebase_core_web/src/firebase_core_web.dart 275:18                                                  initializeApp
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                                            <fn>
dart-sdk/lib/async/zone.dart 1660:54                                                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                                                    handleValue
dart-sdk/lib/async/future_impl.dart 767:44                                                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 796:13                                                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 567:5                                                                     [_completeWithValue]
dart-sdk/lib/async/future.dart 528:22                                                                         <fn>
dart-sdk/lib/async/zone.dart 1660:54                                                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                                                    handleValue
dart-sdk/lib/async/future_impl.dart 767:44                                                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 796:13                                                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 567:5                                                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 640:7                                                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                                                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 177:15                                           <fn>

Removing or commenting out the name parameter doesn't throw the error and all functionalities work properly from plugin example.

darshankawar avatar Jan 27 '23 10:01 darshankawar

/cc @Lyokone

darshankawar avatar Jan 27 '23 10:01 darshankawar

Correct! for now just removing the name parameter will do. I do think that the error itself and the onWaitInitState should be called in a later moment to actually fix the problem

Gorter-dev avatar Jan 27 '23 10:01 Gorter-dev

This is a critical issue for our platform.

We are using the 'name' param to load multiple firebase apps in a web project, thus the 'name' params are a must-have. Is there any timeline for this fix? Or any other solution without downgrading all of our firebase dependencies? We've just updated all our dep.

Thank you!

oantajames avatar Feb 07 '23 18:02 oantajames

@oantajames Thanks for raising this issue. You can use this hotfix in your pubspec.yaml to remove this behavior:

  firebase_auth_web:
    git:
      url: https://github.com/firebase/flutterfire.git
      ref: hotfix/web-user-null
      path: packages/firebase_auth/firebase_auth_web

We are currently waiting for some input from Google to fix the issue #10200 properly

Lyokone avatar Feb 08 '23 08:02 Lyokone

@Lyokone, isn't delaying onWaitInitState a feasible option. Thus also not calling it from a static method.

As it looks to me the await FirebaseAuthWeb.instance.delegate.onWaitInitState() doesn't have to be necessarily called in the static void registerWith.

Gorter-dev avatar Feb 08 '23 14:02 Gorter-dev

Some update for this? I have same issue with firebase_auth: ^4.2.10 firebase_core: ^2.7.1 Example:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    name: DefaultFirebaseOptions.currentPlatform.projectId,
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

Show this error

The following FirebaseException was thrown building MyApp(dirty, state: _MyAppState#ff82d):
[core/no-options] Firebase: Need to provide options, when not being deployed to hosting via source..

If name is null app run correctly

RicharC293 avatar Mar 09 '23 15:03 RicharC293

Have you updated to firebase_auth: ^4.2.10? It should solve this issue.

Lyokone avatar Mar 14 '23 09:03 Lyokone

When running on android or ios, the name tag is required. But with flutter web the name has to be removed. Have been facing this issue for the past two weeks simple because my project is running on this three platforms. I just got it fixed after going through the answers provided above.

Aburafik avatar Apr 07 '23 10:04 Aburafik

Closing out as this has been fixed a while back in firebase_auth => 4.2.10.

russellwheatley avatar Jan 08 '24 17:01 russellwheatley