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

πŸ› [firebase_auth] fetchSignInMethodsForEmail() returns empty list #11508

Closed WalidChebaro closed 1 year ago

WalidChebaro commented 1 year ago

Bug report

Describe the bug The fetchSignInMethodsForEmail() returns an empty list when there is an account with a 'google.com' provider. It should return ['google.com'] however the result is [].

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a user using the signInWithPopup() pass to it GoogleAuthProvider with the following scopes .addScope('https://www.googleapis.com/auth/userinfo.profile'); firebaseGoogleAuthenticationProvider .addScope('https://www.googleapis.com/auth/userinfo.email'); firebaseGoogleAuthenticationProvider .setCustomParameters({'login_hint': 'user@example.com'});
  2. Call the fetchSignInMethodsForEmail() with the same email used to sign in with google
  3. See error or incorrect behavior which is an empty array

Expected behavior

The response should be ['google.com'] and not []

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.13.0, on macOS 13.4.1 22F770820d darwin-arm64, locale en-FR) [βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [βœ“] Xcode - develop for iOS and macOS (Xcode 14.3.1) [βœ“] Chrome - develop for the web [βœ“] Android Studio (version 2022.2) [βœ“] VS Code (version 1.79.0) [βœ“] Connected device (2 available) [βœ“] Network resources β€’ No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 3.1.0 Flutter SDK 3.13.0 chefers 0.0.0+1 dependencies: - app_module 0.0.0+1 [flutter core_module landing_page_module concept_module our_services_module contact_us_module become_partner_chef_module authentication_module flutter_riverpod dartz equatable freezed go_router] - core_module 0.0.0+1 [flutter flutter_localizations intl dartz equatable freezed flutter_riverpod] - cupertino_icons 1.0.5 - dartz 0.10.1 - firebase_module 0.0.0+1 [flutter firebase_core firebase_messaging firebase_crashlytics firebase_analytics firebase_auth dartz riverpod core_module] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_riverpod 2.3.7 [collection flutter meta riverpod state_notifier] - shared_preferences_module 0.0.0+1 [flutter shared_preferences dartz riverpod core_module] dev dependencies: - flutter_lints 2.0.2 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] transitive dependencies: - _fe_analyzer_shared 64.0.0 [meta] - _flutterfire_internals 1.3.5 [collection firebase_core firebase_core_platform_interface flutter meta] - analyzer 6.2.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml] - args 2.4.2 - async 2.11.0 [collection meta] - authentication_module 0.0.0+1 [flutter core_module country_code_module firebase_module http_client_module flutter_riverpod dartz equatable freezed flutter_facebook_auth google_sign_in sign_in_with_apple go_router form_field_validator mask_text_input_formatter pinput retrofit json_annotation] - become_partner_chef_module 0.0.0+1 [flutter flutter_riverpod go_router core_module] - boolean_selector 2.1.1 [source_span string_scanner] - build 2.4.1 [analyzer async convert crypto glob logging meta package_config path] - build_config 1.1.1 [checked_yaml json_annotation path pubspec_parse yaml] - characters 1.3.0 - checked_yaml 2.0.3 [json_annotation source_span yaml] - clock 1.1.1 - collection 1.17.2 - concept_module 0.0.0+1 [flutter flutter_riverpod go_router core_module] - connectivity_plus 4.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm] - connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface] - contact_us_module 0.0.0+1 [flutter flutter_riverpod go_router url_launcher core_module form_field_validator] - convert 3.1.1 [typed_data] - country_code_module 0.1.0+1 [flutter_riverpod core_module flutter flutter_localizations intl json_annotation] - crypto 3.0.3 [typed_data] - dart_style 2.3.2 [analyzer args path pub_semver source_span] - dbus 0.7.8 [args ffi meta xml] - dio 5.3.2 [async http_parser meta path] - equatable 2.0.5 [collection meta] - facebook_auth_desktop 1.0.0 [flutter http flutter_secure_storage flutter_facebook_auth_platform_interface] - fake_async 1.3.1 [clock collection] - ffi 2.1.0 - file 6.1.4 [meta path] - firebase_analytics 10.4.5 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_analytics_platform_interface 3.6.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.4+5 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth 4.7.3 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_auth_platform_interface 6.16.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.6.3 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core 2.15.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.7.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_crashlytics 3.3.5 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace] - firebase_crashlytics_platform_interface 3.6.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_messaging 14.6.6 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_messaging_platform_interface 4.5.5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.5 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - flutter_facebook_auth 6.0.1 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web facebook_auth_desktop] - flutter_facebook_auth_platform_interface 5.0.0 [flutter plugin_platform_interface] - flutter_facebook_auth_web 5.0.0 [flutter flutter_web_plugins js flutter_facebook_auth_platform_interface] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_secure_storage 8.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - 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_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - form_field_validator 1.1.0 [flutter intl] - freezed 2.4.2 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation] - freezed_annotation 2.4.1 [collection json_annotation meta] - glob 2.1.2 [async collection file path string_scanner] - go_router 10.1.0 [collection flutter flutter_web_plugins logging meta] - google_identity_services_web 0.2.1 [js meta] - google_sign_in 6.1.4 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - google_sign_in_android 6.1.18 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.6.2 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.1 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.12.0+3 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - http 1.1.0 [async http_parser meta] - http_client_module 0.0.0+1 [flutter dio connectivity_plus flutter_riverpod core_module firebase_module] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - intl 0.18.1 [clock meta path] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - landing_page_module 0.0.0+1 [flutter flutter_riverpod go_router core_module] - lints 2.1.1 - logging 1.2.0 - mask_text_input_formatter 2.5.0 [flutter] - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - nm 0.5.0 [dbus] - our_services_module 0.0.0+1 [flutter flutter_riverpod go_router core_module] - package_config 2.1.0 [path] - path 1.8.3 - path_provider_linux 2.2.0 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.1.0 [flutter platform plugin_platform_interface] - path_provider_windows 2.2.0 [ffi flutter path path_provider_platform_interface win32] - petitparser 5.4.0 [meta] - pinput 3.0.0 [flutter smart_auth universal_platform] - platform 3.1.1 - plugin_platform_interface 2.1.5 [meta] - pub_semver 2.1.4 [collection meta] - pubspec_parse 1.2.3 [checked_yaml collection json_annotation pub_semver yaml] - quiver 3.2.1 [matcher] - retrofit 4.0.1 [dio meta] - riverpod 2.3.7 [meta stack_trace state_notifier] - shared_preferences 2.2.0 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.2.0 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.3.3 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.3.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.3.0 [flutter plugin_platform_interface] - shared_preferences_web 2.2.0 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.3.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - sign_in_with_apple 5.0.0 [flutter meta sign_in_with_apple_platform_interface sign_in_with_apple_web] - 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 - smart_auth 1.1.1 [flutter flutter_web_plugins] - source_gen 1.4.0 [analyzer async build dart_style glob path source_span yaml] - source_span 1.10.0 [collection path term_glyph] - stack_trace 1.11.0 [path] - state_notifier 1.0.0 [meta] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - typed_data 1.3.2 [collection] - universal_platform 1.0.0+1 - url_launcher 6.1.12 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.0.38 [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.6 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.3 [flutter plugin_platform_interface] - url_launcher_web 2.0.18 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.7 [flutter url_launcher_platform_interface] - vector_math 2.1.4 - watcher 1.1.0 [async path] - web 0.1.4-beta - win32 5.0.6 [ffi] - xdg_directories 1.0.2 [meta path] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

danagbemava-nc commented 1 year ago

Hi @WalidChebaro, I used the plugin example app and modified the _signInWithGoogle method to look like the code below and after a successful login, I get the correct scopes when I call fetchSignInMethodsForEmail. I re-run the test a few times and even deleted the user before trying again, but in all cases, I got the correct scope.

Can you please provide a complete minimal reproducible code sample in a repo that we can clone so that we can investigate this issue?

[log] User(displayName: Pay App, email: payapp54@gmail.c…enantId: null, uid: I2l3XQJxPcepWBg16dSBn8PXxJY2)
[log] sign in methods: [google.com]
Future<void> _signInWithGoogle() async {
    // Trigger the authentication flow
    // final googleUser = await GoogleSignIn(
    //   scopes: ['email', 'profile'],
    // ).signIn();

    // // Obtain the auth details from the request
    // final googleAuth = await googleUser?.authentication;

    // if (googleAuth != null) {
    //   // Create a new credential
    //   final credential = GoogleAuthProvider.credential(
    //     accessToken: googleAuth.accessToken,
    //     idToken: googleAuth.idToken,
    //   );

    //   // Once signed in, return the UserCredential
    //   await auth.signInWithCredential(credential);
    // }
    final authProvider = GoogleAuthProvider();
    authProvider..addScope('email')
    ..addScope('profile');

    authProvider.setCustomParameters({'login_hint': 'user@email.com'});

    if (kIsWeb) {
      await auth.signInWithPopup(authProvider);
    } else {
      await auth.signInWithProvider(authProvider);
    }
  }
WalidChebaro commented 1 year ago

@danagbemava-nc here is the repo https://github.com/Chefers-LTD/temp just provide the required firebase fields to run on a firebase app on the web in the .dev.env file type make init on the terminal run it using vscode choose the "Temp [web] (dev debug)" runner

danagbemava-nc commented 1 year ago

Hi @WalidChebaro, using your code sample, I still get the correct data after signing in. Is your project properly setup on gcp?

Launching lib/main.dart on Chrome in debug mode...
main.dart:1
This app is linked to the debug service: ws://127.0.0.1:61053/_TgZ_yLUwVc=/ws
Debug service listening on ws://127.0.0.1:61053/_TgZ_yLUwVc=/ws
Connecting to VM Service at ws://127.0.0.1:61053/_TgZ_yLUwVc=/ws
[log] null
[GSI_LOGGER-TOKEN_CLIENT]: Instantiated.
[log] TEST SignInMethods [google.com]
WalidChebaro commented 1 year ago

@danagbemava-nc Normally everything is setup correctly on GCP i don't know what could be setup wrong for this not to work i do have a beforeCreate trigger function running but it shouldn't affect this part

danagbemava-nc commented 1 year ago

Hi @WalidChebaro, can you walk me through the whole setup process for your project? Also, do you have this issue with only the google provider?

WalidChebaro commented 1 year ago

Hey @danagbemava-nc, the issue is only with google provider. As for the process i have created a GCP project which i linked to firebase then i enabled firebase auth did a couple of basic configuration and that's it.

danagbemava-nc commented 1 year ago

Hi @WalidChebaro, was the account signed in before the scopes were requested?

Does this happen with every profile? Can you check the metadata of the profile to see what values come up in the providers?

You can get this from currentUser.providerData

WalidChebaro commented 1 year ago

Hey @danagbemava-nc, the account signed in after the scopes were requested you can see this in the code i provided you with. As for every profile i tried another one and i get the same result no provider listed when i create an account using google. [UserInfo(displayName: ... ..., email: ...@gmail.com, phoneNumber: null, photoURL: https://..., providerId: google.com, uid: 104390632695041605894)]

danagbemava-nc commented 1 year ago

Thanks for the info.

One final thing, is this only on web? Or are you experiencing it on other platforms as well?

WalidChebaro commented 1 year ago

Hey @danagbemava-nc i tested it on Android same behavior no providers were retrieved for a google signed in user!

danagbemava-nc commented 1 year ago

Thanks for the info. Labeling for further insight from the team as I cannot reproduce this on my end

\cc @russellwheatley

WalidChebaro commented 1 year ago

@danagbemava-nc @russellwheatley i was able to replicate it by reseting the project. if i enable "Create multiple accounts for each identity provider", instead of "Link accounts that use the same email" i get the empty list! I don't get why this happens though and why i cannot have only one provider per email like we used to have in the past. anyways as i have firebase auth linked to Hasura i will use the beforeCreate function to call my db check if the email exist or not and then use the error message to define if the account exist with this email for a different provider. It's a work around but it will work and i'll keep the setting of "Link accounts that use the same email" to enable the fetchSignInMethodsForEmail() :/

PS: i used to vouch for firebase auth but now i'm not that fund of it anymore anyways i cannot make an auth change now it will harm my business

Yassdrk commented 1 year ago

Hello, I have exactly the same issue. But no matter if i enable "Create multiple accounts for each identity provider" or "Link accounts that use the same email" the array is empty ! Please help, it's a bug !

SatwinderWebethics commented 1 year ago

I am alos getting empty array even user is registered in firebase . it work with google login but not with fetchSignInMethodsForEmail()

russellwheatley commented 1 year ago

Thank you for the reports. We are aware of this issue and I raised an issue on the firebase-ios-sdk here: https://github.com/firebase/firebase-ios-sdk/issues/11810

Could people experience this issue provide information on what platform it is occurring on? I believe it is across platform as I think it is the response from the Firebase server that is causing the issue.

Thanks for the confirmation @WalidChebaro, I will update the issue on the issue created that this is a way to recreate the bug πŸ‘

tolotrasamuel commented 1 year ago

I tested it on flutter macos, and flutter web, both have the same issue.

russellwheatley commented 1 year ago

@tolotrasamuel - It is a Firebase server issue and will be addressed there. I'll update this channel once it is fixed πŸ‘

russellwheatley commented 1 year ago

The reason why and workaround for this issue can be found here: https://github.com/firebase/firebase-ios-sdk/issues/11810#issuecomment-1750523485

I've opened a PR to update documentation,