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_auth]: Unable to complete Google OAuth with web WASM #12819

Open Rexios80 opened 1 month ago

Rexios80 commented 1 month ago

Is there an existing issue for this?

Which plugins are affected?

Auth

Which platforms are affected?

Web

Description

Unable to complete Google OAuth when built with WASM When connected to the emulator, the auth popup window has an error

Reproducing the issue

Attempt to OAuth with google when built with WASM

Firebase Core version

2.31.1

Flutter Version

3.22.0

Relevant Log Output

Error: Auth Emulator Internal Error: No matching frame
    at assert (http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:291:15)
    at http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:339:7
    at sendAuthEventViaIframeRelay (http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:383:12)
    at saveAuthEvent (http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:338:5)
    at finishWithUser (http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:472:3)
    at HTMLLIElement.<anonymous> (http://localhost:9099/emulator/auth/handler?apiKey=API_KEY&appName=%5BDEFAULT%5D&authType=signInViaPopup&redirectUrl=http%3A%2F%2Flocalhost%3A52022%2F&v=10.11.1&eventId=1380118570&providerId=google.com&scopes=profile:447:7)

Flutter dependencies

Expand Flutter dependencies snippet
```yaml Dart SDK 3.5.0-177.0.dev Flutter SDK 3.22.0-42.0.pre.6 pub_stats 1.0.0+1 dependencies: - collection 1.18.0 - fast_ui 0.1.2 [flutter fast_extensions fast_nav fast_overlays fast_rx_flutter fast_rx_persistence] - firebase_analytics 10.10.6 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_app_check 0.2.2+6 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.19.6 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.31.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_database 10.5.6 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter] - firebase_performance 0.9.4+6 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter] - firebase_ui_database 1.4.3 [collection firebase_database firebase_ui_localizations flutter] - fl_chart 0.68.0 [equatable flutter] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine] - flutter_svg 2.0.10+1 [flutter http vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math] - font_awesome_flutter 10.7.0 [flutter] - get_it 7.7.0 [async collection meta] - get_time_ago 1.3.1 [intl] - intl 0.19.0 [clock meta path] - logger 2.3.0 - pub_api_client 2.6.0 [collection freezed_annotation http oauth2 path pubspec] - pub_stats_core 1.0.0 [equatable freezed_annotation http json_annotation pub_api_client] - recase 4.1.0 - sliver_tools 0.2.12 [flutter] - url_launcher 6.2.6 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - web 0.5.1 dev dependencies: - flutter_native_splash 2.4.0 [args flutter flutter_web_plugins html image meta path universal_io xml yaml ansicolor] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service] - rexios_lints 6.0.1 [lints flutter_lints] dependency overrides: - pub_api_client 2.6.0 [collection freezed_annotation http oauth2 path pubspec] transitive dependencies: - _flutterfire_internals 1.3.34 [collection firebase_core firebase_core_platform_interface flutter meta] - ansicolor 2.0.2 - archive 3.6.0 [crypto path] - args 2.5.0 - async 2.11.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - characters 1.3.0 - clock 1.1.1 - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - fast_extensions 0.1.5 [flutter] - fast_nav 0.4.1 [flutter] - fast_overlays 0.1.5 [flutter] - fast_rx 0.6.0 [collection meta] - fast_rx_flutter 0.1.3 [flutter fast_rx] - fast_rx_persistence 0.3.0 [collection fast_rx meta] - firebase_analytics_platform_interface 3.10.7 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.7+6 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins] - firebase_app_check_platform_interface 0.1.0+28 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_app_check_web 0.1.2+6 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins web] - firebase_auth_platform_interface 7.2.7 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.11.6 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web] - firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.17.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web] - firebase_database_platform_interface 0.2.5+34 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_database_web 0.2.5+6 [firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins] - firebase_performance_platform_interface 0.1.4+34 [_flutterfire_internals firebase_core flutter plugin_platform_interface] - firebase_performance_web 0.1.6+6 [_flutterfire_internals firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins] - firebase_ui_localizations 1.11.0 [flutter flutter_localizations path] - flutter_lints 3.0.2 [lints] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math] - freezed_annotation 2.4.1 [collection json_annotation meta] - html 0.15.4 [csslib source_span] - http 1.2.1 [async http_parser meta web] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.2.0 [archive meta xml] - json_annotation 4.9.0 [meta] - leak_tracker 10.0.5 [clock collection meta path vm_service] - leak_tracker_flutter_testing 3.0.5 [flutter leak_tracker leak_tracker_testing matcher meta] - leak_tracker_testing 3.0.1 [leak_tracker matcher meta] - lints 3.0.0 - matcher 0.12.16+1 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.11.1 [collection] - meta 1.14.0 - oauth2 2.0.2 [collection crypto http http_parser] - path 1.9.0 - path_parsing 1.0.1 [vector_math meta] - petitparser 6.0.2 [meta] - plugin_platform_interface 2.1.8 [meta] - pub_semver 2.1.4 [collection meta] - pubspec 2.3.0 [path pub_semver yaml uri] - quiver 3.2.1 [matcher] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - stack_trace 1.11.1 [path] - stream_channel 2.1.2 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.7.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - universal_io 2.2.2 [collection meta typed_data] - uri 1.0.0 [matcher quiver] - url_launcher_android 6.3.2 [flutter url_launcher_platform_interface] - url_launcher_ios 6.3.0 [flutter url_launcher_platform_interface] - url_launcher_linux 3.1.1 [flutter url_launcher_platform_interface] - url_launcher_macos 3.2.0 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.3.2 [flutter plugin_platform_interface] - url_launcher_web 2.3.1 [flutter flutter_web_plugins url_launcher_platform_interface web] - url_launcher_windows 3.1.1 [flutter url_launcher_platform_interface] - vector_graphics 1.1.11+1 [flutter http vector_graphics_codec] - vector_graphics_codec 1.1.11+1 - vector_graphics_compiler 1.1.11+1 [args meta path_parsing xml vector_graphics_codec path] - vector_math 2.1.4 - vm_service 14.2.2 - xml 6.5.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

Additional context and comments

No response

cynthiajoan commented 1 month ago

FYI @Rexios80 I marked away your apiKey, please be mindful while posting those in the issues.

Rexios80 commented 1 month ago

Meh they're basically public information, I have it heavily restricted, and I have App Check enabled but thanks for looking out for me

Lyokone commented 1 month ago

Hello @Rexios80, I was wondering which commands you are using to get this issue, does it only happen using emulator? I don't see Google Sign In in your dependencies, are you using another way to complete Google OAuth?

Rexios80 commented 1 month ago
await FirebaseAuth.instance.signInWithPopup(GoogleAuthProvider());

This happens on a deployed site as well as the emulator. Here is a deployed version of my site with the issue: https://beta.pubstats.dev (make sure to run in chrome or it might not actually be WASM)

The repo for that site is here: https://github.com/Rexios80/pub_stats Here is the line: https://github.com/Rexios80/pub_stats/blob/bedf51898154e9fe9f63c9dd61db59a049184f72/pub_stats/lib/controller/user_controller.dart#L29

Lyokone commented 1 month ago

Thanks, I'll have another look with what you provided

Lyokone commented 1 month ago

@Rexios80 I've tried with this example

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
      options: const FirebaseOptions(
    apiKey: 'AIzaSyB7wZb2tO1-Fs6GbDADUSTs2Qs3w08Hovw',
    appId: '1:406099696497:web:87e25e51afe982cd3574d0',
    messagingSenderId: '406099696497',
    projectId: 'flutterfire-e2e-tests',
    authDomain: 'flutterfire-e2e-tests.firebaseapp.com',
    databaseURL:
        'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app',
    storageBucket: 'flutterfire-e2e-tests.appspot.com',
    measurementId: 'G-JN95N1JV2E',
  ));
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Google Sign In Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const SignInDemo(),
    );
  }
}

class SignInDemo extends StatefulWidget {
  const SignInDemo({super.key});

  @override
  _SignInDemoState createState() => _SignInDemoState();
}

class _SignInDemoState extends State<SignInDemo> {
  User? _user;

  Future<void> _signInWithGoogle() async {
    final data =
        await FirebaseAuth.instance.signInWithPopup(GoogleAuthProvider());
    print(data);
  }

  Future<void> _signOut() async {
    await FirebaseAuth.instance.signOut();
    setState(() {
      _user = null;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Google Sign In Demo'),
      ),
      body: Center(
        child: _user == null
            ? ElevatedButton(
                onPressed: _signInWithGoogle,
                child: const Text('Sign in with Google'),
              )
            : Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('Signed in as ${_user?.displayName}'),
                  ElevatedButton(
                    onPressed: _signOut,
                    child: const Text('Sign out'),
                  ),
                ],
              ),
      ),
    );
  }
}

And I was able to complete the Sign In successfully 🤔 Can you try with my example?

Rexios80 commented 1 month ago

The initializeApp call doesn't even work on Flutter stable, and that code has the same issue on Flutter master. Are you sure you ran with WASM using the instructions here: https://docs.flutter.dev/platform-integration/web/wasm#serving-wasm-locally

Or if you are on Flutter master you can run with flutter run -d chrome --wasm

Lyokone commented 1 month ago

Yes

Flutter is already up to date on channel stable
Flutter 3.22.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision a14f74ff3a (6 days ago) • 2024-05-22 11:08:21 -0500
Engine • revision 55eae6864b
Tools • Dart 3.4.1 • DevTools 2.34.3
flutter build web --wasm
serve build/web

If you say the initializeApp don't work on stable, you probably have an issue with your setup.

ekasetiawans commented 1 month ago

I also facing the issue with latest flutter stable

Rexios80 commented 1 month ago

I'm not sure what exactly could be wrong with my setup

Can you confirm that bool.fromEnvironment('FLUTTER_WEB_USE_SKWASM') is true?

Rexios80 commented 1 month ago

The initializeApp issue is probably the same as https://github.com/firebase/flutterfire/issues/12623 which I'm not sure has landed in stable

Lyokone commented 1 month ago

Thanks @Rexios80 for your patience, finally reproduced on my end. I was using serve which doesn't seem to serve directly WASM instead of dhttpd.

Lyokone commented 1 month ago

I've tried a couple of things, even tried the official google_sign_in package. It wouldn't even render the button to sign in in web 🤔 Not sure how to help you with this issue, I'll raise it internally.

Rexios80 commented 1 month ago

Thanks for looking into it. Flutter WASM definitely has growing pains. I just want to raise awareness of the issues.

kevmoo commented 2 weeks ago

Please double check with the latest release of Flutter/Dart.

https://github.com/flutter/flutter/blob/master/docs/releases/Hotfixes-to-the-Stable-Channel.md#3222-june-06-2024

Lyokone commented 2 weeks ago

Doesn't work on stable or master on my end

Rexios80 commented 2 weeks ago

Confirmed NOT working on Flutter 3.22.2

kevmoo commented 2 weeks ago

Could you post the stack trace with --no-strip-wasm set?

Rexios80 commented 2 weeks ago

This is the only relevant log, but I'm pretty sure it's just caused by the login failing and not related to why it is failing

main.dart.mjs:56 [firebase_auth/popup-closed-by-user] The popup has been closed by the user before finalizing the operation.
main.dart.mjs:56 
main.dart.wasm:0x102d34 Uncaught Exception {}[[Prototype]]: WebAssembly.Exception
$Error._throw @ main.dart.wasm:0x102d34
$Error._throwWithCurrentStackTrace @ main.dart.wasm:0x102d05
$_invokeCallback @ main.dart.wasm:0x100c09
(anonymous) @ main.dart.mjs:693
setTimeout (async)
poll @ popup.ts:310
setTimeout (async)
poll @ popup.ts:216
pollUserCancellation @ popup.ts:216
onExecution @ popup.ts:279
await in onExecution (async)
(anonymous) @ abstract_popup_redirect_operation.ts:77
await in (anonymous) (async)
execute @ abstract_popup_redirect_operation.ts:72
executeNotNull @ popup.ts:237
signInWithPopup @ popup.ts:141
_1829 @ main.dart.mjs:544
$FirebaseAuthWeb.signInWithPopup closure at file:///Users/rexios/.pub-cache/hosted/pub.dev/firebase_auth_web-5.12.0/lib/firebase_auth_web.dart:438:7 @ main.dart.wasm:0x1c1bbe
$closure wrapper at file:///Users/rexios/.pub-cache/hosted/pub.dev/firebase_auth_web-5.12.0/lib/firebase_auth_web.dart:438:7 trampoline @ main.dart.wasm:0x1c1d43
$guardAuthExceptions @ main.dart.wasm:0x1872a4
$FirebaseAuthWeb.signInWithPopup inner @ main.dart.wasm:0x1c1c9b
$FirebaseAuthWeb.signInWithPopup @ main.dart.wasm:0x1c1ad3
$FirebaseAuth.signInWithPopup inner @ main.dart.wasm:0x1c193c
$UserController.signInWithGoogle inner @ main.dart.wasm:0x1c1832
$UserController.signInWithGoogle @ main.dart.wasm:0x1c1740
$UserController.signInWithGoogle tear-off trampoline @ main.dart.wasm:0x1c1769
$_InkResponseState.handleTap @ main.dart.wasm:0x1fd7ad
$_InkResponseState.handleTap tear-off trampoline @ main.dart.wasm:0x1fd7ce
$GestureRecognizer.invokeCallback @ main.dart.wasm:0x1d9801
$TapGestureRecognizer.handleTapUp @ main.dart.wasm:0x1d9e6f
$BaseTapGestureRecognizer._checkUp @ main.dart.wasm:0x1d9d99
$BaseTapGestureRecognizer.handlePrimaryPointer @ main.dart.wasm:0x1dbb29
$PrimaryPointerGestureRecognizer.handleEvent @ main.dart.wasm:0x1db6bc
$PrimaryPointerGestureRecognizer.handleEvent tear-off trampoline @ main.dart.wasm:0x1db6f5
$PointerRouter._dispatchEventToRoutes closure at file:///Users/rexios/fvm/versions/3.22.2/packages/flutter/lib/src/gestures/pointer_router.dart:141:26 @ main.dart.wasm:0x123b8b
$closure wrapper at file:///Users/rexios/fvm/versions/3.22.2/packages/flutter/lib/src/gestures/pointer_router.dart:141:26 trampoline @ main.dart.wasm:0x123c0a
$__CompactLinkedIdentityHashMap&_HashFieldBase&MapMixin&_HashBase&_IdenticalAndIdentityHashCode&_LinkedHashMapMixin.forEach @ main.dart.wasm:0x105766
$PointerRouter._dispatchEventToRoutes @ main.dart.wasm:0x123b1d
$PointerRouter.route @ main.dart.wasm:0x123a96
$_WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent @ main.dart.wasm:0x234f0e
$_WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue @ main.dart.wasm:0x12377e
$_WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket @ main.dart.wasm:0x274840
$_WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket tear-off trampoline @ main.dart.wasm:0x2748b7
$invoke1 @ main.dart.wasm:0x126579
$ClickDebouncer._sendToFramework @ main.dart.wasm:0x22caf5
$ClickDebouncer.onPointerData @ main.dart.wasm:0x278d20
$ClickDebouncer.onPointerData tear-off trampoline @ main.dart.wasm:0x278e94
$_PointerAdapter.setup closure at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:993:58 @ main.dart.wasm:0x27702a
$closure wrapper at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:993:58 trampoline @ main.dart.wasm:0x277947
$_PointerAdapter._addPointerEventListener closure at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:925:41 @ main.dart.wasm:0x2797fd
$closure wrapper at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:925:41 trampoline @ main.dart.wasm:0x279827
$_BaseAdapter.addEventListener closure at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:515:25 @ main.dart.wasm:0x279b28
$closure wrapper at org-dartlang-sdk:///lib/_engine/engine/pointer_binding.dart:515:25 trampoline @ main.dart.wasm:0x279b54
$_2044 @ main.dart.wasm:0x100a1c
(anonymous) @ main.dart.mjs:290