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

πŸ› [FirebaseAuth] userChanges returns an anonymous user after calling linkWithCredential on iOS #3920

Closed jezsung closed 3 years ago

jezsung commented 4 years ago

Bug report

userChanges stream returns an anonymous user after calling linkWithCredential() to promote a current anonymous user to a permanent user. This only happens on iOS. userChanges returns a correct signed user on Android.

Steps to reproduce

Steps to reproduce the behavior:

  1. Sign in anonymously by calling signInAnonymously()
  2. Promote the anonymous user to a permanent user
    final email = 'example@gmail.com';
    final password = '123456';
    final credential = EmailAuthProvider.credential(email: email, password: password);
    FirebaseAuth.instance.currentUser.linkWithCredential(credential);
  3. Listen to FirebaseAuth.instance.userChanges() and log the user.

    Expected behavior

The returned user should be the signed user. But it returns an anonymous user on iOS. It works fine on Android.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [βœ“] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.4 19E287, locale ko-KR) β€’ Flutter version 1.22.2 at /Users/*******/Developer/flutter β€’ Framework revision 84f3d28555 (4 days ago), 2020-10-15 16:26:19 -0700 β€’ Engine revision b8752bbfff β€’ Dart version 2.10.2 [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /Users/*******/Library/Android/sdk β€’ Platform android-29, build-tools 29.0.3 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 11.5) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 11.5, Build version 11E608c β€’ CocoaPods version 1.9.3 [βœ“] Android Studio (version 3.6) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin version 45.1.1 β€’ Dart plugin version 192.7761 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [βœ“] Connected device (1 available) β€’ ****** iPhone (mobile) β€’ 48006f05f9f84f9f0771134bb1d76016876695a3 β€’ ios β€’ iOS 13.5.1 [βœ“] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.4 19E287, locale ko-KR) β€’ Flutter version 1.22.2 at /Users/******/Developer/flutter β€’ Framework revision 84f3d28555 (4 days ago), 2020-10-15 16:26:19 -0700 β€’ Engine revision b8752bbfff β€’ Dart version 2.10.2 [βœ“] Android toolchain - develop for Android devices (Android SDK version 29.0.3) β€’ Android SDK at /Users/******/Library/Android/sdk β€’ Platform android-29, build-tools 29.0.3 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 11.5) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 11.5, Build version 11E608c β€’ CocoaPods version 1.9.3 [βœ“] Android Studio (version 3.6) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin version 45.1.1 β€’ Dart plugin version 192.7761 β€’ Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211) [βœ“] Connected device (1 available) β€’ ****** iPhone (mobile) β€’ 48006f05f9f84f9f0771134bb1d76016876695a3 β€’ ios β€’ iOS 13.5.1 β€’ No issues found! ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.10.2 Flutter SDK 1.22.2 myapp 1.0.0+1 dependencies: - carousel_slider 2.2.1 [flutter] - cloud_firestore 0.14.1+3 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - device_preview 0.4.8 [font_awesome_flutter http freezed_annotation json_annotation flutter flutter_localizations meta shared_preferences shared_preferences_macos] - equatable 1.2.4 [collection meta] - extended_image 1.1.1 [flutter extended_image_library meta] - file_picker 2.0.8 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface] - firebase_analytics 6.0.2 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.18.1+2 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.5.0+1 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_crashlytics 0.2.1+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface] - firebase_messaging 7.0.3 [meta flutter firebase_core] - firebase_storage 4.0.1 [flutter firebase_core] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_bloc 6.0.4 [flutter bloc provider] - flutter_linkify 3.1.3 [flutter linkify] - flutter_signin_button 1.1.0 [flutter font_awesome_flutter] - flutter_widget_from_html 0.5.1 [cached_network_image chewie flutter flutter_layout_grid flutter_svg flutter_widget_from_html_core html url_launcher video_player webview_flutter] - fluttertoast 7.0.4 [flutter flutter_web_plugins] - get_it 4.0.4 [async meta] - google_sign_in 4.5.4 [google_sign_in_platform_interface flutter meta google_sign_in_web] - http 0.12.2 [http_parser path pedantic] - image_cropper 1.3.1 [flutter] - intl 0.16.1 [path] - material_design_icons_flutter 4.0.5555 [flutter] - path 1.8.0-nullsafety.1 - path_provider 1.6.18 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows] - share 0.6.5+2 [meta mime flutter] - shared_preferences 0.5.12+2 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows] - shimmer 1.1.2 [flutter] - timeago 2.0.27 - url_launcher 5.5.3 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos] - webview_flutter 1.0.1 [flutter] dev dependencies: - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] transitive dependencies: - async 2.5.0-nullsafety.1 [collection] - bloc 6.0.2 [meta] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - cached_network_image 2.3.2+1 [flutter flutter_cache_manager octo_image] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - chewie 0.9.10 [open_iconic_flutter video_player wakelock flutter] - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 2.1.2 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.0+4 [flutter flutter_web_plugins firebase http_parser meta firebase_core cloud_firestore_platform_interface js] - collection 1.15.0-nullsafety.3 - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - csslib 0.16.2 [source_span] - extended_image_library 0.3.0 [flutter path_provider http_client_helper crypto path] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.0 [http http_parser js] - firebase_analytics_platform_interface 1.0.3 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_auth_platform_interface 2.1.1 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.1+1 [flutter flutter_web_plugins firebase meta http_parser intl firebase_core firebase_auth_platform_interface js] - firebase_core_platform_interface 2.0.0 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.0 [firebase firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_crashlytics_platform_interface 1.1.1 [flutter meta collection firebase_core plugin_platform_interface] - flutter_blurhash 0.5.0 [flutter meta] - flutter_cache_manager 1.4.2 [flutter path_provider uuid http path sqflite pedantic clock file rxdart] - flutter_layout_grid 0.10.2 [collection flutter meta quiver] - flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math] - flutter_plugin_android_lifecycle 1.0.11 [flutter] - flutter_svg 0.18.1 [path_drawing xml vector_math meta flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - flutter_widget_from_html_core 0.5.1 [flutter html] - font_awesome_flutter 8.8.1 [flutter] - freezed_annotation 0.11.0+1 [collection json_annotation meta] - google_sign_in_platform_interface 1.1.2 [flutter meta quiver] - google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js] - html 0.14.0+4 [csslib source_span] - http_client_helper 0.2.1 [http] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - js 0.6.2 - json_annotation 3.0.1 - linkify 2.1.0 - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - mime 0.9.7 - nested 0.0.4 [flutter] - octo_image 0.3.0 [flutter flutter_blurhash] - open_iconic_flutter 0.3.0 [flutter] - path_drawing 0.4.1+1 [vector_math meta path_parsing flutter] - path_parsing 0.1.4 [vector_math meta] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+3 [flutter] - path_provider_platform_interface 1.0.3 [flutter meta platform plugin_platform_interface] - path_provider_windows 0.0.4+1 [path_provider_platform_interface meta path flutter ffi win32] - pedantic 1.9.0 - petitparser 3.1.0 [meta] - platform 2.2.1 - platform_detect 1.4.0 [meta pub_semver] - plugin_platform_interface 1.0.2 [meta] - process 3.0.13 [file intl meta path platform] - provider 4.3.2+1 [flutter nested collection] - pub_semver 1.4.4 [collection] - quiver 2.1.3 [matcher meta] - rxdart 0.24.1 - shared_preferences_linux 0.0.2+2 [file flutter meta path path_provider_linux shared_preferences_platform_interface] - shared_preferences_macos 0.0.1+10 [shared_preferences_platform_interface flutter] - shared_preferences_platform_interface 1.0.4 [meta flutter] - shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta] - shared_preferences_windows 0.0.1+1 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows] - sky_engine 0.0.99 - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite 1.3.1+1 [flutter sqflite_common path] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - string_scanner 1.1.0-nullsafety.1 [charcode source_span] - synchronized 2.2.0+2 - term_glyph 1.2.0-nullsafety.1 - test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.0-nullsafety.3 [collection] - url_launcher_linux 0.0.1+1 [flutter] - url_launcher_macos 0.0.1+7 [flutter] - url_launcher_platform_interface 1.0.8 [flutter meta plugin_platform_interface] - url_launcher_web 0.1.3+2 [url_launcher_platform_interface platform_detect flutter flutter_web_plugins meta] - uuid 2.2.2 [crypto convert] - vector_math 2.1.0-nullsafety.3 - video_player 0.10.12+5 [meta video_player_platform_interface video_player_web flutter] - video_player_platform_interface 2.2.0 [flutter meta] - video_player_web 0.1.4 [flutter flutter_web_plugins meta video_player_platform_interface] - wakelock 0.1.4+2 [flutter] - win32 1.7.3 [ffi] - xdg_directories 0.1.0 [path process flutter] - xml 4.5.1 [collection convert meta petitparser] ```

jesper372 commented 3 years ago

I'm seeing this as well. It breaks my entire authentication flow; I'm effectively unable to update my app state when an anonymous user registers with an email and password. Is there a workaround? Or a fix coming soon? I've tried calling signInWithEmailAndPassword after linkWithCredential; doing so generally doesn't result in the email-authenticated user appearing in userChanges (but for some reason, sometimes does).

The above is specific to iOS - I haven't seen it in Android (where userChanges seemingly always gets updated with the email-authenticated user right after the call to linkWithCredential).

I'm using 0.18.4+1.

jezsung commented 3 years ago

@jesper372 You can call FirebaseAuth.instance.currentUser.reload() after linkWithCredential(). It returns the correct signed user.

jesper372 commented 3 years ago

@jezsung Thanks!

russellwheatley commented 3 years ago

Hey @jezsung, is this still an issue on the latest auth package?

  firebase_core: "^1.1.0"
  firebase_auth: "^1.1.3"
google-oss-bot commented 3 years ago

Hey @jezsung. 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!

jezsung commented 3 years ago

@russellwheatley Sorry for the late reply, I haven't used the userChanges stream in the latest development. I found it updating the user's status based on the provided stream has some tradeoff and I eventually went for another approach. So I'm not sure if the bug presents in the latest version of Firebase. I hope someone can investigate it.

google-oss-bot commented 3 years ago

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

@jezsung 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.