flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [firebase_auth] Getting error when calling getRedirectResult on Web

Open peupompeu opened this issue 1 year ago • 5 comments

Bug report

After using FirebaseAuth.instance.signInWithRedirect(googleProvider) in flutter web, when the signIn flow concludes, i was redirected to my app, when i try calling FirebaseAuth.instance.getRedirectResult(); I am getting the following error:

Error: Expected a value of type 'FutureOr', but got one of type 'Null' at Object.throw_ [as throw] (http://localhost:38321/dart_sdk.js:5080:11) at Object.castError (http://localhost:38321/dart_sdk.js:5039:15) at Object.cast [as as] (http://localhost:38321/dart_sdk.js:5356:17) at FutureOr.as_FutureOr (http://localhost:38321/dart_sdk.js:4683:21) at _AsyncCompleter.new.complete (http://localhost:38321/dart_sdk.js:35321:55) at http://localhost:38321/dart_sdk.js:62418:96

This is the expected behavior? can't find clear documentation on this topic..

Running in debug mode.

Steps to reproduce

Steps to reproduce the behavior:

  1. Initialize firebase_core on main function await Firebase.initializeApp( options: [firebase_options], ); 2 Call the FirebaseAuth.instance.getRedirectResult() on flutter web final UserCredential userCredential = await FirebaseAuth.instance.getRedirectResult();
  2. See error or incorrect behavior

Expected behavior

Retrieve UserCredential as expected.

Additional context

firebase_core: ^1.20.0 firebase_auth: ^3.6.2 extension_google_sign_in_as_googleapis_auth: ^2.0.6


Flutter doctor

Click To Expand
[✓] Flutter (Channel stable, 3.0.5, on Ubuntu 22.04.1 LTS 5.15.0-43-generic,
    locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio
[✓] VS Code
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

Flutter dependencies

Click To Expand
Dart SDK 2.17.6
Flutter SDK 3.0.5
quike_business 1.0.5+9

dependencies:
- android_intent_plus 3.1.1 [flutter platform meta]
- android_long_task 1.0.0 [flutter]
- animated_text_kit 4.2.2 [flutter characters]
- audioplayers 1.0.1 [audioplayers_android audioplayers_darwin audioplayers_linux audioplayers_platform_interface audioplayers_web audioplayers_windows flutter http path_provider uuid]
- aurora 1.0.0 [flutter]
- bloc 8.0.3 [meta]
- cupertino_icons 1.0.5
- dartz 0.10.1
- extension_google_sign_in_as_googleapis_auth 2.0.6 [flutter google_sign_in googleapis_auth http meta]
- firebase_analytics 9.3.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 3.6.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.20.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_messaging 12.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_storage 10.3.4 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_background 1.1.0 [flutter]
- flutter_bloc 8.0.1 [flutter bloc provider]
- flutter_foreground_task 3.8.1 [flutter platform shared_preferences shared_preferences_android shared_preferences_ios]
- flutter_keyboard_visibility 5.3.0 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flutter]
- flutter_local_notifications 9.7.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_polyline_points 1.0.0 [flutter http]
- flutter_spinkit 5.1.0 [flutter]
- form_field_validator 1.1.0 [flutter intl]
- freezed_annotation 2.1.0 [collection json_annotation meta]
- geolocator 9.0.1 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- get_it 7.2.0 [async collection]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- google_maps_flutter 2.1.9 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface]
- google_maps_flutter_web 0.4.0+1 [flutter flutter_web_plugins google_maps google_maps_flutter_platform_interface sanitize_html stream_transform]
- google_sign_in 5.4.0 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- googleapis 9.1.0 [_discoveryapis_commons http]
- graphql 5.1.1 [meta path gql gql_exec gql_link gql_http_link gql_transform_link gql_error_link gql_dedupe_link hive normalize http collection web_socket_channel stream_channel rxdart uuid]
- hive 2.2.3 [meta crypto]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- http 0.13.4 [async http_parser meta path]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- injectable 1.5.3 [get_it]
- intl 0.17.0 [clock path]
- json_annotation 4.6.0 [meta]
- location 4.4.0 [flutter location_platform_interface location_web]
- mask_text_input_formatter 2.3.0 [flutter]
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- pointer_interceptor 0.9.3+2 [flutter]
- pull_to_refresh 2.0.0 [flutter]
- qr_flutter 4.0.0 [flutter qr]
- responsive_builder 0.4.2 [flutter]
- rich_text_controller 1.4.0 [flutter]
- rive 0.9.1 [collection flutter graphs http meta]
- rxdart 0.27.5
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shimmer 2.0.0 [flutter]
- sign_in_with_apple 4.1.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web]
- swipable_stack 2.0.0 [flutter sprung]
- timeago 3.2.2
- url_launcher 6.1.5 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 3.0.6 [crypto]

dev dependencies:
- analyzer 4.3.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- build_runner 2.2.0 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- flutter_launcher_icons 0.9.3 [args image path yaml]
- flutter_lints 2.0.1 [lints]
- flutter_native_splash 2.2.6 [args flutter flutter_web_plugins image js lint meta path universal_io xml yaml]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- freezed 2.1.0+1 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- hive_generator 1.1.3 [build source_gen hive analyzer source_helper]
- injectable_generator 1.5.4 [build source_gen path glob analyzer code_builder dart_style injectable collection]
- json_serializable 6.3.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]

dependency overrides:
- analyzer 4.3.1 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]

transitive dependencies:
- _discoveryapis_commons 1.0.3 [http http_parser meta]
- _fe_analyzer_shared 43.0.0 [meta]
- archive 3.3.1 [crypto path]
- args 2.3.1
- async 2.8.2 [collection meta]
- audioplayers_android 1.0.1 [audioplayers_platform_interface flutter]
- audioplayers_darwin 1.0.1 [audioplayers_platform_interface flutter]
- audioplayers_linux 1.0.0 [audioplayers_platform_interface flutter]
- audioplayers_platform_interface 1.0.0 [flutter plugin_platform_interface]
- audioplayers_web 1.0.0 [audioplayers_platform_interface flutter flutter_web_plugins]
- audioplayers_windows 1.0.0 [audioplayers_platform_interface flutter]
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.3.0 [analyzer async convert crypto glob logging meta path]
- build_config 1.1.0 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.0.9 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.2.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.4.0 [built_collection collection fixnum meta]
- characters 1.2.0
- charcode 1.3.1
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- clock 1.1.0
- code_builder 4.1.0 [built_collection built_value collection matcher meta]
- collection 1.16.0
- convert 3.0.2 [typed_data]
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- csslib 0.17.2 [source_span]
- dart_style 2.2.3 [analyzer args path pub_semver source_span]
- dbus 0.7.7 [args ffi meta xml]
- fake_async 1.3.0 [clock collection]
- ffi 2.0.1
- file 6.1.2 [meta path]
- firebase_analytics_platform_interface 3.3.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.2 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.5.2 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 4.2.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.5.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_messaging_platform_interface 4.1.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.1.0 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_storage_platform_interface 4.1.12 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.3.2 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.1
- flutter_keyboard_visibility_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- flutter_keyboard_visibility_web 2.0.0 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter]
- flutter_local_notifications_linux 0.5.0+1 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- frontend_server_client 2.1.3 [async path]
- geolocator_android 4.0.2 [flutter geolocator_platform_interface]
- geolocator_apple 2.2.1 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.0.6 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.1.1 [flutter geolocator_platform_interface]
- glob 2.1.0 [async collection file path string_scanner]
- google_maps 6.2.0 [js_wrapping meta]
- google_maps_flutter_platform_interface 2.2.1 [collection flutter plugin_platform_interface stream_transform]
- google_sign_in_android 6.0.1 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.4.0 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.2.0 [flutter quiver]
- google_sign_in_web 0.10.2 [flutter flutter_web_plugins google_sign_in_platform_interface js]
- googleapis_auth 1.3.1 [crypto http http_parser]
- gql 0.13.1 [collection meta source_span]
- gql_dedupe_link 2.0.2 [async gql_exec gql_link meta]
- gql_error_link 0.2.2 [async gql_exec gql_link meta]
- gql_exec 0.4.0 [collection gql meta]
- gql_http_link 0.4.2 [gql gql_exec gql_link http http_parser meta]
- gql_link 0.4.2 [gql gql_exec meta]
- gql_transform_link 0.2.2 [gql_exec gql_link]
- graphs 2.1.0 [collection]
- html 0.15.0 [csslib source_span]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image 3.2.0 [archive meta xml]
- image_picker_android 0.8.5+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+6 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- io 1.0.3 [meta path string_scanner]
- js 0.6.4
- js_wrapping 0.7.4 [js]
- lint 1.10.0
- lints 2.0.0
- location_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- location_web 3.1.1 [flutter flutter_web_plugins http_parser js location_platform_interface meta]
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- mime 1.0.2
- nested 1.0.0 [flutter]
- normalize 0.6.0+1 [gql collection]
- package_config 2.1.0 [path]
- path 1.8.1
- path_provider_android 2.0.16 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- petitparser 5.0.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- pool 1.5.1 [async stack_trace]
- process 4.2.4 [file path platform]
- provider 6.0.3 [collection flutter nested]
- pub_semver 2.1.1 [collection meta]
- pubspec_parse 1.2.0 [checked_yaml collection json_annotation pub_semver yaml]
- qr 2.1.0 [meta]
- quiver 3.1.0 [matcher]
- sanitize_html 2.0.0 [html meta]
- shared_preferences_android 2.0.12 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.3.1 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 1.0.2 [shelf stream_channel web_socket_channel]
- sign_in_with_apple_platform_interface 1.0.0 [flutter plugin_platform_interface meta]
- sign_in_with_apple_web 1.0.1 [flutter flutter_web_plugins sign_in_with_apple_platform_interface js]
- sky_engine 0.0.99
- source_gen 1.2.2 [analyzer async build dart_style glob meta path source_span yaml]
- source_helper 1.3.2 [analyzer collection source_gen]
- source_span 1.8.2 [collection path term_glyph]
- sprung 3.0.0 [flutter]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- timing 1.0.0 [json_annotation]
- typed_data 1.3.1 [collection]
- universal_io 2.0.4 [collection crypto meta typed_data]
- url_launcher_android 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.0 [flutter plugin_platform_interface]
- url_launcher_web 2.0.12 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- vector_math 2.1.2
- watcher 1.0.1 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 6.1.0 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]

Minimal reproducible

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

import 'firebase_options.dart';

void main() async {
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  UserCredential userCredential =
      await FirebaseAuth.instance.getRedirectResult();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

peupompeu avatar Aug 06 '22 03:08 peupompeu

@pepomps Can you provide the complete error message and log along with a minimal code sample that shows this error ? Also, is this in debug or in release mode ?

darshankawar avatar Aug 08 '22 08:08 darshankawar

@darshankawar Complete error: Error: Expected a value of type 'FutureOr<UserCredentialJsImpl>', but got one of type 'Null' at Object.throw_ [as throw] (http://localhost:38321/dart_sdk.js:5080:11) at Object.castError (http://localhost:38321/dart_sdk.js:5039:15) at Object.cast [as as] (http://localhost:38321/dart_sdk.js:5356:17) at FutureOr.as_FutureOr (http://localhost:38321/dart_sdk.js:4683:21) at _AsyncCompleter.new.complete (http://localhost:38321/dart_sdk.js:35321:55) at http://localhost:38321/dart_sdk.js:62418:96

Minimal code sample: https://github.com/pepomps/firebase_auth

Running in debug mode here!

peupompeu avatar Aug 08 '22 13:08 peupompeu

Thanks for the update. Can you try as below and see if it works or gives you same error ?

UserCredential user = await auth.signInWithPopup(provider);
await auth.signInWithRedirect(provider);
UserCredential user = await auth.getRedirectResult();

darshankawar avatar Aug 09 '22 10:08 darshankawar

Thanks for the help so far @darshankawar!

After the suggestion, tried to run the code in some different states. When using signInWithRedirect on web, we are redirected to another page. Out off our main code flow, after being redirected back, the main code runs again.

If we follow the expected flow: Main -> signInWithRedirect -> "Provider flow" -> "Main" -> getRedirectResult: Works as expected But if we follow the flow: Main -> getRedirectResult: Error

In the second case, the getRedirectResult is used to detect if my main code is running after a signInWithRedirect attempt. If it is, we get the user, If not, we get the error mentioned above.

How we could conditionally run getRedirectResult if we are getting a new dart flow after the redirection?

One possible solution is to save in async storage a flag when i call signInWithRedirect. Then when we are redirected back, check the flag before running getRedirectResult.

Another option is to set the redirect back to a specified path that runs getRedirectResult when called.

Or just run getRedirectResult every app start, catch the error and assume that i got it because the user hasn't tried a signIn.

In your opinion what's the best approach? another suggestion?

peupompeu avatar Aug 09 '22 13:08 peupompeu

If we follow the expected flow: Main -> signInWithRedirect -> "Provider flow" -> "Main" -> getRedirectResult: Works as expected But if we follow the flow: Main -> getRedirectResult: Error

I think the first option is an expected flow, because, since, you are getting a null while directly using the method, it may be expecting an object, which it is unable to find and hence the error. That is being taken care in the first option, as we are providing a provider.

Alternatively you can try to use signInWithRedirect to keep the authentication process in the same window and see if it works in your case.

darshankawar avatar Aug 10 '22 06:08 darshankawar

Thanks for the help @darshankawar. Got it!!

peupompeu avatar Aug 10 '22 18:08 peupompeu