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.69k stars 3.97k forks source link

πŸ› [firebase_auth_web] Login is not working #10987

Closed arisAlexis closed 6 months ago

arisAlexis commented 1 year ago

Bug report

Describe the bug Login is not working after the first user login it crashes.

Error:

Error: Expected a value of type 'firebase_auth.Error', but got one of type 'NativeError'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 121:3   castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart 245:34   as
packages/firebase_auth_web/firebase_auth_web.dart 487:57                      useAuthEmulator
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 463:31                      useAuthEmulator
packages/firebase_auth/src/firebase_auth.dart 142:21                          useAuthEmulator
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/src/firebase_auth.dart 131:31                          useAuthEmulator
packages/risa/main.dart 47:33                                                 main$
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1661:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 784:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 813:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 584:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 657: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>

The error happens in auth.dart here:

Future<void> onWaitInitState() async {
    final completer = Completer();
    final nextWrapper = allowInterop((auth_interop.UserJsImpl? user) {
      _initUser = User.getInstance(user);
      completer.complete();
    });

Steps to reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. '...'
  3. See error or incorrect behavior

Expected behavior

Login

Sample project

void main() async {
  await Helper.loadDotEnv();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  await FirebaseAppCheck.instance.activate(
      // webRecaptchaSiteKey: dotenv.env["RECAPTCHA_KEY"],
      webRecaptchaSiteKey: "",
      androidProvider:
          kDebugMode ? AndroidProvider.debug : AndroidProvider.playIntegrity);

  //emulators
  if (kDebugMode) {
    String? host;
    if (kIsWeb) {
      host = "127.0.0.1"; //tried also to specify localhost
    } else {
      host = "10.0.2.2";
    }
    FirebaseFirestore.instance.useFirestoreEmulator(host, 8080);
    FirebaseFunctions.instance.useFunctionsEmulator(host, 5001);
    await FirebaseAuth.instance.useAuthEmulator(host, 9099);
    await FirebaseStorage.instance.useStorageEmulator(host, 9199);
    await FirebaseFirestore.instance.clearPersistence();
  }

  if (kIsWeb) {
    await FirebaseAuth.instance.setPersistence(Persistence.LOCAL);
    // await FirebaseAuth.instance.authStateChanges().first;
  }

  // initial loading

  if (FirebaseAuth.instance.currentUser != null) {
    initialRoute = "/places";
  } else {
    initialRoute = "/welcome";
  }
  runApp(const MyApp());
}

Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.22621.1702], locale en-US) [βœ“] Windows Version (Installed version of Windows is version 10 or higher) [βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [βœ“] Chrome - develop for the web [βœ“] Visual Studio - develop for Windows (Visual Studio Build Tools 2022 17.5.4) [βœ“] Android Studio (version 2022.1) [βœ“] Android Studio [βœ“] VS Code (version 1.78.2) [βœ“] Connected device (3 available) [βœ“] Network resources β€’ No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` β”œβ”€β”€ audioplayers 3.0.1 β”‚ β”œβ”€β”€ audioplayers_android 2.0.0 β”‚ β”‚ β”œβ”€β”€ audioplayers_platform_interface... β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ audioplayers_darwin 3.0.1 β”‚ β”‚ β”œβ”€β”€ audioplayers_platform_interface... β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ audioplayers_linux 1.0.4 β”‚ β”‚ β”œβ”€β”€ audioplayers_platform_interface... β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ audioplayers_platform_interface 4.0.0 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ audioplayers_web 2.2.0 β”‚ β”‚ β”œβ”€β”€ audioplayers_platform_interface... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ β”œβ”€β”€ audioplayers_windows 1.1.3 β”‚ β”‚ β”œβ”€β”€ audioplayers_platform_interface... β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ http 0.13.6 β”‚ β”‚ β”œβ”€β”€ async... β”‚ β”‚ β”œβ”€β”€ http_parser... β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ flutter... β”‚ β”œβ”€β”€ path_provider... β”‚ └── uuid... β”œβ”€β”€ cloud_firestore 4.7.0 β”‚ β”œβ”€β”€ cloud_firestore_platform_interface 5.14.0 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ cloud_firestore_web 3.5.0 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ cloud_firestore_platform_interface... β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ β”œβ”€β”€ collection... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ β”œβ”€β”€ flutter... β”‚ └── meta... β”œβ”€β”€ cloud_functions 4.3.0 β”‚ β”œβ”€β”€ cloud_functions_platform_interface 5.4.0 β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ cloud_functions_web 4.5.0 β”‚ β”‚ β”œβ”€β”€ cloud_functions_platform_interface... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ └── flutter... β”œβ”€β”€ cupertino_icons 1.0.5 β”œβ”€β”€ firebase_analytics 10.4.0 β”‚ β”œβ”€β”€ firebase_analytics_platform_interface 3.6.0 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ firebase_analytics_web 0.5.4 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ firebase_analytics_platform_interface... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ └── flutter... β”œβ”€β”€ firebase_app_check 0.1.4 β”‚ β”œβ”€β”€ firebase_app_check_platform_interface 0.0.8 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ firebase_app_check_web 0.0.10 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ firebase_app_check_platform_interface... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ └── flutter... β”œβ”€β”€ firebase_auth 4.6.0 β”‚ β”œβ”€β”€ firebase_auth_platform_interface 6.15.0 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals 1.3.0 β”‚ β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ firebase_auth_web 5.5.0 β”‚ β”‚ β”œβ”€β”€ http_parser 4.0.2 β”‚ β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”‚ β”œβ”€β”€ source_span... β”‚ β”‚ β”‚ β”œβ”€β”€ string_scanner... β”‚ β”‚ β”‚ └── typed_data... β”‚ β”‚ β”œβ”€β”€ firebase_auth_platform_interface... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ β”œβ”€β”€ flutter... β”‚ └── meta... β”œβ”€β”€ firebase_core 2.12.0 β”‚ β”œβ”€β”€ firebase_core_platform_interface 4.8.0 β”‚ β”‚ β”œβ”€β”€ plugin_platform_interface 2.1.4 β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_test... β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ firebase_core_web 2.5.0 β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins 0.0.0 β”‚ β”‚ β”‚ β”œβ”€β”€ characters... β”‚ β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ β”‚ β”œβ”€β”€ material_color_utilities... β”‚ β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ β”‚ └── vector_math... β”‚ β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ flutter... β”‚ └── meta... β”œβ”€β”€ firebase_storage 11.2.0 β”‚ β”œβ”€β”€ firebase_storage_platform_interface 4.4.0 β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ firebase_storage_web 3.6.0 β”‚ β”‚ β”œβ”€β”€ _flutterfire_internals... β”‚ β”‚ β”œβ”€β”€ async... β”‚ β”‚ β”œβ”€β”€ firebase_core... β”‚ β”‚ β”œβ”€β”€ firebase_core_web... β”‚ β”‚ β”œβ”€β”€ firebase_storage_platform_interface... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ β”œβ”€β”€ http... β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ firebase_core... β”‚ β”œβ”€β”€ firebase_core_platform_interface... β”‚ └── flutter... β”œβ”€β”€ flutter 0.0.0 β”‚ β”œβ”€β”€ characters 1.3.0 β”‚ β”œβ”€β”€ collection 1.17.1 β”‚ β”œβ”€β”€ js 0.6.7 β”‚ β”‚ └── meta... β”‚ β”œβ”€β”€ material_color_utilities 0.2.0 β”‚ β”œβ”€β”€ meta 1.9.1 β”‚ β”œβ”€β”€ sky_engine 0.0.99 β”‚ └── vector_math 2.1.4 β”œβ”€β”€ flutter_dotenv 5.0.2 β”‚ └── flutter... β”œβ”€β”€ flutter_easyloading 3.0.5 β”‚ β”œβ”€β”€ flutter_spinkit 5.2.0 β”‚ β”‚ └── flutter... β”‚ └── flutter... β”œβ”€β”€ flutter_facebook_auth 5.0.11 β”‚ β”œβ”€β”€ facebook_auth_desktop 0.0.9 β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage 8.0.0 β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_linux 1.1.3 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”‚ └── flutter_secure_storage_platform_interface... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_macos 3.0.0 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”‚ └── flutter_secure_storage_platform_interface... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_platform_interface 1.0.1 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”‚ └── plugin_platform_interface... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_web 1.1.1 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_platform_interface... β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ β”‚ β”‚ └── js... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter_secure_storage_windows 2.0.0 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ β”‚ └── flutter_secure_storage_platform_interface... β”‚ β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_facebook_auth_platform_interface... β”‚ β”‚ └── http... β”‚ β”œβ”€β”€ flutter_facebook_auth_platform_interface 4.1.1 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ flutter_facebook_auth_web 4.1.1 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_facebook_auth_platform_interface... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── js... β”‚ └── flutter... β”œβ”€β”€ flutter_image_compress 1.1.3 β”‚ └── flutter... β”œβ”€β”€ flutter_lints 2.0.1 β”‚ └── lints 2.1.0 β”œβ”€β”€ flutter_login 4.1.1 β”‚ β”œβ”€β”€ another_flushbar 1.12.30 β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ another_transformer_page_view 2.0.1 β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ quiver 3.2.1 β”‚ β”‚ └── matcher... β”‚ β”œβ”€β”€ sign_in_button 3.2.0 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── font_awesome_flutter... β”‚ β”œβ”€β”€ flutter... β”‚ β”œβ”€β”€ font_awesome_flutter... β”‚ β”œβ”€β”€ provider... β”‚ └── url_launcher... β”œβ”€β”€ flutter_test 0.0.0 β”‚ β”œβ”€β”€ boolean_selector 2.1.1 β”‚ β”‚ β”œβ”€β”€ source_span... β”‚ β”‚ └── string_scanner... β”‚ β”œβ”€β”€ clock 1.1.1 β”‚ β”œβ”€β”€ fake_async 1.3.1 β”‚ β”‚ β”œβ”€β”€ clock... β”‚ β”‚ └── collection... β”‚ β”œβ”€β”€ matcher 0.12.15 β”‚ β”‚ β”œβ”€β”€ async... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ β”œβ”€β”€ stack_trace... β”‚ β”‚ β”œβ”€β”€ term_glyph... β”‚ β”‚ └── test_api... β”‚ β”œβ”€β”€ path 1.8.3 β”‚ β”œβ”€β”€ source_span 1.9.1 β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ └── term_glyph... β”‚ β”œβ”€β”€ stack_trace 1.11.0 β”‚ β”‚ └── path... β”‚ β”œβ”€β”€ string_scanner 1.2.0 β”‚ β”‚ └── source_span... β”‚ β”œβ”€β”€ term_glyph 1.2.1 β”‚ β”œβ”€β”€ test_api 0.5.1 β”‚ β”‚ β”œβ”€β”€ async... β”‚ β”‚ β”œβ”€β”€ boolean_selector... β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”œβ”€β”€ matcher... β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ β”œβ”€β”€ source_span... β”‚ β”‚ β”œβ”€β”€ stack_trace... β”‚ β”‚ β”œβ”€β”€ stream_channel... β”‚ β”‚ β”œβ”€β”€ string_scanner... β”‚ β”‚ └── term_glyph... β”‚ β”œβ”€β”€ async... β”‚ β”œβ”€β”€ characters... β”‚ β”œβ”€β”€ collection... β”‚ β”œβ”€β”€ flutter... β”‚ β”œβ”€β”€ js... β”‚ β”œβ”€β”€ material_color_utilities... β”‚ β”œβ”€β”€ meta... β”‚ β”œβ”€β”€ stream_channel... β”‚ └── vector_math... β”œβ”€β”€ flutter_webrtc 0.9.29+hotfix.1 β”‚ β”œβ”€β”€ dart_webrtc 1.0.16 β”‚ β”‚ β”œβ”€β”€ platform_detect 2.0.7 β”‚ β”‚ β”‚ β”œβ”€β”€ pub_semver 2.1.4 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ collection... β”‚ β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ └── webrtc_interface... β”‚ β”œβ”€β”€ webrtc_interface 1.0.13 β”‚ β”œβ”€β”€ collection... β”‚ β”œβ”€β”€ flutter... β”‚ β”œβ”€β”€ js... β”‚ └── path_provider... β”œβ”€β”€ font_awesome_flutter 10.4.0 β”‚ └── flutter... β”œβ”€β”€ image_picker 0.8.7+5 β”‚ β”œβ”€β”€ image_picker_android 0.8.6+14 β”‚ β”‚ β”œβ”€β”€ flutter_plugin_android_lifecycle 2.0.14 β”‚ β”‚ β”‚ └── flutter... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── image_picker_platform_interface... β”‚ β”œβ”€β”€ image_picker_for_web 2.1.12 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── image_picker_platform_interface... β”‚ β”œβ”€β”€ image_picker_ios 0.8.7+4 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── image_picker_platform_interface... β”‚ β”œβ”€β”€ image_picker_platform_interface 2.6.3 β”‚ β”‚ β”œβ”€β”€ cross_file 0.3.3+4 β”‚ β”‚ β”‚ β”œβ”€β”€ js... β”‚ β”‚ β”‚ └── meta... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ http... β”‚ β”‚ └── plugin_platform_interface... β”‚ └── flutter... β”œβ”€β”€ path_provider 2.0.15 β”‚ β”œβ”€β”€ path_provider_android 2.0.27 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── path_provider_platform_interface... β”‚ β”œβ”€β”€ path_provider_foundation 2.2.3 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── path_provider_platform_interface... β”‚ β”œβ”€β”€ path_provider_linux 2.1.10 β”‚ β”‚ β”œβ”€β”€ ffi 2.0.2 β”‚ β”‚ β”œβ”€β”€ xdg_directories 1.0.0 β”‚ β”‚ β”‚ β”œβ”€β”€ process 4.2.4 β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ file... β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ β”‚ β”‚ └── platform... β”‚ β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ β”‚ └── path... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ └── path_provider_platform_interface... β”‚ β”œβ”€β”€ path_provider_platform_interface 2.0.6 β”‚ β”‚ β”œβ”€β”€ platform 3.1.0 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ path_provider_windows 2.1.6 β”‚ β”‚ β”œβ”€β”€ win32 4.1.4 β”‚ β”‚ β”‚ └── ffi... β”‚ β”‚ β”œβ”€β”€ ffi... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ └── path_provider_platform_interface... β”‚ └── flutter... β”œβ”€β”€ provider 6.0.5 β”‚ β”œβ”€β”€ nested 1.0.0 β”‚ β”‚ └── flutter... β”‚ β”œβ”€β”€ collection... β”‚ └── flutter... β”œβ”€β”€ rflutter_alert 2.0.4 β”‚ └── flutter... β”œβ”€β”€ shared_preferences 2.1.1 β”‚ β”œβ”€β”€ shared_preferences_android 2.1.4 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── shared_preferences_platform_interface... β”‚ β”œβ”€β”€ shared_preferences_foundation 2.2.2 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── shared_preferences_platform_interface... β”‚ β”œβ”€β”€ shared_preferences_linux 2.2.0 β”‚ β”‚ β”œβ”€β”€ file 6.1.4 β”‚ β”‚ β”‚ β”œβ”€β”€ meta... β”‚ β”‚ β”‚ └── path... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ β”œβ”€β”€ path_provider_linux... β”‚ β”‚ β”œβ”€β”€ path_provider_platform_interface... β”‚ β”‚ └── shared_preferences_platform_interface... β”‚ β”œβ”€β”€ shared_preferences_platform_interface 2.2.0 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ shared_preferences_web 2.1.0 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── shared_preferences_platform_interface... β”‚ β”œβ”€β”€ shared_preferences_windows 2.2.0 β”‚ β”‚ β”œβ”€β”€ file... β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ path... β”‚ β”‚ β”œβ”€β”€ path_provider_platform_interface... β”‚ β”‚ β”œβ”€β”€ path_provider_windows... β”‚ β”‚ └── shared_preferences_platform_interface... β”‚ └── flutter... β”œβ”€β”€ url_launcher 6.1.11 β”‚ β”œβ”€β”€ url_launcher_android 6.0.33 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ β”œβ”€β”€ url_launcher_ios 6.1.4 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ β”œβ”€β”€ url_launcher_linux 3.0.5 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ β”œβ”€β”€ url_launcher_macos 3.0.5 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ β”œβ”€β”€ url_launcher_platform_interface 2.1.2 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── plugin_platform_interface... β”‚ β”œβ”€β”€ url_launcher_web 2.0.16 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ β”œβ”€β”€ flutter_web_plugins... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ β”œβ”€β”€ url_launcher_windows 3.0.6 β”‚ β”‚ β”œβ”€β”€ flutter... β”‚ β”‚ └── url_launcher_platform_interface... β”‚ └── flutter... β”œβ”€β”€ uuid 3.0.7 β”‚ └── crypto 3.0.3 β”‚ └── typed_data 1.3.2 β”‚ └── collection... └── web_socket_channel 2.4.0 β”œβ”€β”€ async 2.11.0 β”‚ β”œβ”€β”€ collection... β”‚ └── meta... β”œβ”€β”€ stream_channel 2.1.1 β”‚ └── async... └── crypto... ```

darshankawar commented 1 year ago

Thanks for the report @arisAlexis

void main() async {
  await Helper.loadDotEnv();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

I think await Firebase.initializeApp has to be the first line inside main(), but you have await Helper.loadDotEnv();. Can you reorder and see if it helps ?

arisAlexis commented 1 year ago

commented out the line completely, no difference. First run it logs in the user correctly. Second run that the user is already logged in and this error appears. In the error there is the "authEmulator" wording, I don't understand how is this relevant.

arisAlexis commented 1 year ago

update: it works on production so as it says in the error there is some problem with the authEmulator. There have been many issues with the authEmulator and login/relogin sequences, I think you should prioritize this.

To summarize:

Everything works fine with android/ios emulators and the authEmulator. When I fire up the web I get this error. If I comment out the line to use the authEmulator and it hits production then it works.

darshankawar commented 1 year ago

Thanks for the update. Keeping this issue open for team's attention and input.

/cc @Lyokone

arisAlexis commented 1 year ago

I think this is relevant #10200

IncognitoGK9 commented 1 year ago

I am also facing the same issue for over two weeks for web. The authEmular is not stable. restarts, log out/login, taskKill for the ports to open, the java.exe remains open, all these make use of the emulator a very painful experience yet it is supposed to help quickly test. Please prioritize. The open java.exe window also hangs and have to click on it, press enter many times for it to wake up.

arisAlexis commented 1 year ago

@Lyokone this is killing everyone developing with emulators and using the web target, pretty significant for adoption imo. Please prioritize.

IncognitoGK9 commented 1 year ago

I discovered a littel secret whenever I face an AuthEmulator error. Assuming all your set ups are ok and it has been working before, I do the following procedure to restart the emulators and they now do pick the web authentication:

  1. Close running web browser instance for the web application
  2. If you had not stopped the emulators, stop them using CTRL + C (do not close the the emulators by closing the java window, do this after CTRL + C,
  3. Run on a command prompt this command: netstat -ano | findstr :**_8080_** (replace the port you are using for the emulator).
  4. If the processes are still running, then identify the process ID and run: taskkill /PID **_21222_** /F (note that the number 21222 is your process ID as shown by running the findstrcommand.
  5. Log out of firebase: firebase logout
  6. Log into firebase: firebase login
  7. Update firebase (not necessary if you have done it recently): npm install -g firebase-tools
  8. Start your emulators: firebase emulators:start

Those steps helps a lot to clean up the whole emulator (you can run the emulator start with other flags e.g. export/import, project etc, like I run it like this: firebase emulators:start --project bwerere-2020 --import=./dir --export-on-exit and it works now with no issue.

arisAlexis commented 1 year ago

thanks. this is unlikely to help because my problem is very specific. One there is a logged in user and you are using the authEmulator the web crashes. If you are not logged in, it works and it crashes the next time. This can't be a clean up issue.

arisAlexis commented 1 year ago

@Lyokone @darshankawar this is a really big issue for web development that Google is trying to promote. If you can't login with an emulator locally, development is dead. Can you give higher priority?

russellwheatley commented 1 year ago

Have you updated the emulators? i.e. run npm install -g firebase-tools

arisAlexis commented 1 year ago

@russellwheatley yes latest everything new emulators. As I said I think this is relevant https://github.com/firebase/flutterfire/issues/10200. When the user is currently logged in the emulator and you rerun the app then it fails and only for the web.

pogorv12 commented 1 year ago

Same issue ...

Error: Expected a value of type 'firebase_auth.Error', but got one of type 'NativeError'

at await auth.useAuthEmulator('localhost', 9099); on

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  app = await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  auth = FirebaseAuth.instanceFor(app: app);

  if (shouldUseFirebaseEmulator) {
    await auth.useAuthEmulator('localhost', 9099);
  }
  runApp(AuthApp());
}

it happens when auth initially was done to firebase server, occasionally or in purpose, and later auth emulator was enabled.

To overcome the issue, signoff should be done first and then emulator works fine.

kNoAPP commented 1 year ago

I am also getting this error suddenly after changing nothing in my app startup in the last 5 months. I have not been able to resolve it. The error only occurs on the emulator and not for cloud instances. Running firebase cli v12.4.3, firebase auth v4.6.3, flutter v3.10.5, and dart 3.0.5.

Error: Expected a value of type 'firebase_auth.Error', but got one of type 'NativeError'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 121:3   castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart 245:34   as
packages/firebase_auth_web/firebase_auth_web.dart 490:57                      useAuthEmulator
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 466:31                      useAuthEmulator
packages/firebase_auth/src/firebase_auth.dart 142:21                          useAuthEmulator
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/src/firebase_auth.dart 131:31                          useAuthEmulator
packages/myth/main.dart 84:33                                               _startup
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  // The last Firebase initialization action should be to check if we're running
  // in emulated mode, and if so, use the Firebase emulators instead of the
  // cloud database.
  if (!environmentVariables.firebaseCloud) {
    await FirebaseAuth.instance.useAuthEmulator(remote, 9099); // error throws on this line for web
    FirebaseFirestore.instance.useFirestoreEmulator(remote, 8080);
    await FirebaseFirestore.instance.clearPersistence();
    FirebaseFunctions.instance.useFunctionsEmulator(remote, 5001);
  }
  runApp(AuthApp());
}

Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.23)
[√] Android Studio (version 2022.1)
[√] VS Code (version 1.80.0)
[√] Connected device (3 available)
[√] Network resources

β€’ No issues found!
pogorv12 commented 1 year ago

Same issue ...

Error: Expected a value of type 'firebase_auth.Error', but got one of type 'NativeError'

at await auth.useAuthEmulator('localhost', 9099); on

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  app = await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  auth = FirebaseAuth.instanceFor(app: app);

  if (shouldUseFirebaseEmulator) {
    await auth.useAuthEmulator('localhost', 9099);
  }
  runApp(AuthApp());
}

it happens when auth initially was done to firebase server, occasionally or in purpose, and later auth emulator was enabled.

To overcome the issue, signoff should be done first and then emulator works fine.

Managed to establish the failure path...

  1. Emulator is working and user managed to login
  2. Everything works fine while page reloads initiated by IDE (VS Code in my case). Auth Emulator notification is shown at the screen bottom.
  3. Everything broke when user occasionally/in purpose press refresh button in browser. After browser refresh, emulator message disappears and app connects to firebase servers.
  4. If user make login attempt after step 3, it will be authenticated on firebase server, not on emulator, and it's authentication state will be remembered by browser.
  5. All page reloads initiated by IDE will fail after 4, because of auth initialization will failure on emulator as the browser probably store wrong auth info.
  6. To heal the issue, user need to connect to firebase server and make logoff. Browser refresh as no code solution helps well in this -).
  7. After when firebase auth data is wiped in browser, the auth emulator attempts succeed.
luiznpi commented 7 months ago

Lets hope this issue is not marked as closed before a solution is provided.

Lyokone commented 7 months ago

@arisAlexis I think this issue was fixed by https://github.com/firebase/flutterfire/pull/10766 and https://github.com/firebase/flutterfire/pull/11247

Testing it locally it looks okay for me. Let me know if you still are reproducing the issue.

google-oss-bot commented 7 months ago

Hey @arisAlexis. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 6 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@arisAlexis if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.