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] User I am getting back is always Null UserInfo.uid (package:firebase_auth_platform_interface/src/user_info.dart:52:24) #5813

Closed balasubramanian1612s closed 3 years ago

balasubramanian1612s commented 3 years ago

I reproduced the minimal code which produces same error.

UI

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:folkEvents/provider/auth_provider.dart';
import 'package:provider/provider.dart';

class UserEmailInputScreen extends StatefulWidget {
  static const routeName = 'user-email-input';
  @override
  _UserEmailInputScreenState createState() => _UserEmailInputScreenState();
}

class _UserEmailInputScreenState extends State<UserEmailInputScreen> {
  @override
  Widget build(BuildContext context) {
    final _authProvider = Provider.of<AuthProvider>(context, listen: true);
    return FutureBuilder(
      future: AuthProvider.initializeFirebase(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return Text('Error initializing Firebase');
        } else if (snapshot.connectionState == ConnectionState.done) {
          return OutlinedButton(
            style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(Colors.white),
              shape: MaterialStateProperty.all(
                RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(40),
                ),
              ),
            ),
            onPressed: () async {
              User user = (await _authProvider.googleSignInAndLink())!;
              print(user);
            },
            child: Padding(
              padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(left: 10),
                    child: Text(
                      'Sign in with Google',
                      style: TextStyle(
                        fontSize: 20,
                        color: Colors.black54,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  )
                ],
              ),
            ),
          );
        }
        return CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(
            Colors.orange,
          ),
        );
      },
    );
  }
}

AuthProvider.dart

class AuthProvider with ChangeNotifier {

  static Future<FirebaseApp> initializeFirebase() async {
    FirebaseApp firebaseApp = await Firebase.initializeApp();

    // TODO: Add auto login logic

    return firebaseApp;
  }

Future<User?> googleSignInAndLink({bool? isLinked = true}) async {
    FirebaseAuth auth = FirebaseAuth.instance;
    User? user;

    if (kIsWeb) {
      GoogleAuthProvider authProvider = GoogleAuthProvider();

      try {
        final UserCredential userCredential =
            await auth.signInWithPopup(authProvider);

        user = userCredential.user;
      } catch (e) {
        print(e);
      }
    } else {
      final GoogleSignIn googleSignIn = GoogleSignIn();

      final GoogleSignInAccount? googleSignInAccount =
          await googleSignIn.signIn();

      if (googleSignInAccount != null) {
        final GoogleSignInAuthentication googleSignInAuthentication =
            await googleSignInAccount.authentication;

        final AuthCredential credential = GoogleAuthProvider.credential(
          accessToken: googleSignInAuthentication.accessToken,
          idToken: googleSignInAuthentication.idToken,
        );

        try {
          final UserCredential userCredential =
              await auth.signInWithCredential(credential);

          user = userCredential.user;
        } on FirebaseAuthException catch (e) {
          if (e.code == 'account-exists-with-different-credential') {
            // ...
          } else if (e.code == 'invalid-credential') {
            // ...
          }
        } catch (e) {
          // ...
        }
      }
    }

    return user;
}
}

Screen Shot 2021-04-18 at 5 59 22 PM

pankaj-nikam commented 3 years ago

Please fix this. I am getting the same in Phone Auth too.

markusaksli-nc commented 3 years ago

Hi @balasubramanian1612s Could you please provide your flutter doctor -v and flutter pub deps -- --style=compact? Thank you

balasubramanian1612s commented 3 years ago

### flutter doctor -v

Screen Shot 2021-04-19 at 2 11 18 PM

flutter pub deps -- --style=compact

Dart SDK 2.12.3
Flutter SDK 2.0.5
folkEvents 2.1.3+40

dependencies:
- animated_text_kit 4.1.1 [flutter characters]
- cached_network_image 3.0.0 [flutter flutter_cache_manager octo_image]
- carousel_slider 4.0.0-nullsafety.0 [flutter]
- cloud_firestore 1.0.4 [cloud_firestore_platform_interface cloud_firestore_web firebase_core firebase_core_platform_interface flutter meta]
- csc_picker 0.2.3 [flutter]
- csv 5.0.0
- cupertino_icons 1.0.2
- day_night_time_picker 1.0.1 [flutter]
- device_info 2.0.0 [flutter device_info_platform_interface]
- dio 4.0.0 [http_parser path]
- duration_picker 1.0.1 [pedantic flutter]
- email_validator 2.0.1
- excel 2.0.0-null-safety [archive xml equatable]
- firebase_auth 1.1.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_auth_oauth 1.0.1 [flutter firebase_auth firebase_core firebase_auth_oauth_platform_interface firebase_auth_oauth_web]
- firebase_core 1.0.3 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.0.0 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_dynamic_links 2.0.0-dev.1 [firebase_core flutter]
- firebase_messaging 9.1.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_local_notifications 5.0.0+1 [flutter flutter_local_notifications_platform_interface platform timezone]
- flutter_native_timezone 1.0.10 [flutter]
- flutter_secure_storage 4.1.0 [meta flutter]
- flutter_slidable 0.6.0-nullsafety.0 [flutter]
- flutter_speed_dial 3.0.5 [flutter]
- flutter_svg 0.21.0 [flutter meta path_drawing vector_math xml]
- flutter_widget_from_html 0.6.0-rc.2021031201 [flutter flutter_widget_from_html_core fwfh_cached_network_image fwfh_chewie fwfh_svg fwfh_url_launcher fwfh_webview html]
- fluttertoast 8.0.3 [flutter flutter_web_plugins]
- focused_menu 1.0.5 [flutter]
- future_progress_dialog 0.2.0 [flutter]
- get 4.1.3 [flutter]
- get_it 6.0.0 [async collection]
- google_sign_in 5.0.1 [google_sign_in_platform_interface google_sign_in_web flutter meta]
- http 0.13.1 [http_parser meta path pedantic]
- intl 0.17.0 [clock path]
- jiffy 4.1.0 [intl]
- material_design_icons_flutter 5.0.5955-rc.1 [flutter]
- numberpicker 2.0.1 [flutter]
- open_file 3.1.0 [flutter ffi]
- package_info 2.0.0 [flutter]
- path_provider 2.0.1 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- percent_indicator 3.3.0-nullsafety.1 [flutter]
- permission_handler 6.1.1 [flutter meta permission_handler_platform_interface]
- pin_input_text_field 4.0.0 [flutter]
- provider 5.0.0 [collection flutter nested]
- qr_code_scanner 0.4.0 [flutter]
- qr_flutter 4.0.0 [flutter qr]
- share 2.0.1 [meta mime flutter]
- shared_preferences 2.0.5 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- sign_in_with_apple 3.0.0 [flutter meta]
- stack_trace 1.10.0 [path]
- syncfusion_flutter_charts 19.1.56 [flutter intl vector_math syncfusion_flutter_core]
- table_calendar 3.0.0 [flutter intl simple_gesture_detector]
- timeago 3.0.2
- transparent_image 2.0.0
- url_launcher 6.0.3 [flutter url_launcher_platform_interface url_launcher_linux url_launcher_macos url_launcher_windows url_launcher_web]
- youtube_player_flutter 8.0.0 [flutter flutter_inappwebview]

dev dependencies:
- flutter_launcher_icons 0.9.0 [args image path yaml]
- 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:
- archive 3.1.2 [crypto path]
- args 2.0.0
- async 2.5.0 [collection]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.2.0
- chewie 1.0.0 [cupertino_icons flutter video_player wakelock]
- clock 1.1.0
- cloud_firestore_platform_interface 4.0.1 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 1.0.4 [cloud_firestore_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.15.0
- crypto 3.0.1 [collection typed_data]
- csslib 0.17.0 [source_span]
- device_info_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- equatable 2.0.0 [collection meta]
- fake_async 1.2.0 [clock collection]
- ffi 1.0.0
- file 6.1.0 [meta path]
- firebase 9.0.1 [http http_parser js]
- firebase_auth_oauth_platform_interface 1.0.0 [flutter firebase_auth firebase_core]
- firebase_auth_oauth_web 1.0.0 [flutter flutter_web_plugins firebase firebase_auth firebase_core firebase_auth_oauth_platform_interface js]
- firebase_auth_platform_interface 4.1.0 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 1.0.6 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.0.0 [flutter meta plugin_platform_interface]
- firebase_core_web 1.0.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.0.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 2.1.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 1.0.4 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- flutter_blurhash 0.6.0 [flutter meta pedantic]
- flutter_cache_manager 3.0.1 [clock collection file flutter http image path path_provider pedantic rxdart sqflite uuid]
- flutter_inappwebview 5.3.2 [flutter]
- flutter_local_notifications_platform_interface 3.0.0 [flutter plugin_platform_interface]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- flutter_widget_from_html_core 0.6.0-rc.2021031201 [flutter html]
- fwfh_cached_network_image 0.6.0-rc.2021030401 [cached_network_image flutter flutter_widget_from_html_core]
- fwfh_chewie 0.6.0-rc.2021030202 [chewie flutter flutter_widget_from_html_core video_player]
- fwfh_svg 0.6.0-rc.2021031201 [flutter flutter_svg flutter_widget_from_html_core]
- fwfh_url_launcher 0.6.0-rc.2021022601 [flutter flutter_widget_from_html_core url_launcher]
- fwfh_webview 0.6.0-rc.2021031201 [flutter flutter_widget_from_html_core webview_flutter]
- google_sign_in_platform_interface 2.0.1 [flutter meta quiver]
- google_sign_in_web 0.10.0 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- html 0.15.0 [csslib source_span]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.0.2 [archive meta xml]
- js 0.6.3
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- mime 1.0.0
- nested 1.0.0 [flutter]
- octo_image 1.0.0+1 [flutter flutter_blurhash]
- path 1.8.0
- path_drawing 0.5.0 [vector_math meta path_parsing flutter]
- path_parsing 0.2.0 [vector_math meta]
- path_provider_linux 2.0.0 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 2.0.0 [flutter]
- path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.0 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.11.0
- permission_handler_platform_interface 3.1.1 [flutter meta plugin_platform_interface]
- petitparser 4.1.0 [meta]
- platform 3.0.0
- plugin_platform_interface 2.0.0 [meta]
- process 4.2.1 [file path platform]
- qr 2.0.0 [meta]
- quiver 3.0.1 [matcher]
- rxdart 0.26.0
- shared_preferences_linux 2.0.0 [flutter file meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 2.0.0 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 2.0.0 [flutter]
- shared_preferences_web 2.0.0 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 2.0.0 [shared_preferences_platform_interface flutter file meta path path_provider_platform_interface path_provider_windows]
- simple_gesture_detector 0.2.0 [flutter]
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- sqflite 2.0.0+3 [flutter sqflite_common path]
- sqflite_common 2.0.0+2 [synchronized path meta]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- syncfusion_flutter_core 19.1.56 [vector_math flutter]
- synchronized 3.0.0
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.7.0 [path]
- typed_data 1.3.0 [collection]
- url_launcher_linux 2.0.0 [flutter]
- url_launcher_macos 2.0.0 [flutter]
- url_launcher_platform_interface 2.0.2 [flutter plugin_platform_interface]
- url_launcher_web 2.0.0 [url_launcher_platform_interface meta flutter flutter_web_plugins]
- url_launcher_windows 2.0.0 [flutter]
- uuid 3.0.4 [crypto]
- vector_math 2.1.0
- video_player 2.1.1 [meta video_player_platform_interface video_player_web flutter flutter_test]
- video_player_platform_interface 4.1.0 [flutter meta flutter_test]
- video_player_web 2.0.0 [flutter flutter_web_plugins meta video_player_platform_interface]
- wakelock 0.4.0 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web]
- wakelock_macos 0.1.0 [flutter flutter_web_plugins wakelock_platform_interface]
- wakelock_platform_interface 0.2.0 [flutter meta]
- wakelock_web 0.2.0 [flutter flutter_web_plugins js wakelock_platform_interface]
- webview_flutter 2.0.3 [flutter]
- win32 2.0.5 [ffi]
- xdg_directories 0.2.0 [meta path process]
- xml 5.1.0 [collection meta petitparser]
- yaml 3.1.0 [collection source_span string_scanner]
balasubramanian1612s commented 3 years ago

Please check this out @markusaksli-nc. Thank you

markusaksli-nc commented 3 years ago

Wasn't able to reproduce this exact case but the issue is a duplicate of https://github.com/FirebaseExtended/flutterfire/issues/5218