firebase / FirebaseUI-Flutter

Apache License 2.0
92 stars 79 forks source link

🐛 [firebase_ui_auth] EmailVerifiedAction can't trigger callback after verify email #221

Open Trung15010802 opened 6 months ago

Trung15010802 commented 6 months ago

Is there an existing issue for this?

What plugin is this bug for?

Firebase UI Auth

What platform(s) does this bug affect?

Android

List of dependencies used.

flutter pub deps -s list
dependencies:
- flutter 0.0.0
  - characters 1.3.0
  - collection 1.18.0
  - material_color_utilities 0.5.0
  - meta 1.10.0
  - vector_math 2.1.4
  - web 0.3.0
  - sky_engine any
- cupertino_icons 1.0.6
- flutter_svg 2.0.9
  - flutter any
  - vector_graphics ^1.1.9+1
  - vector_graphics_codec ^1.1.9+1
  - vector_graphics_compiler ^1.1.9+1
- change_app_package_name 1.1.0
- firebase_core 2.24.2
  - firebase_core_platform_interface ^5.0.0
  - firebase_core_web ^2.10.0
  - flutter any
  - meta ^1.8.0
- firebase_ui_auth 1.11.0
  - email_validator ^2.1.17
  - firebase_auth ^4.15.0
  - firebase_core ^2.24.0
  - firebase_dynamic_links ^5.4.6
  - firebase_ui_localizations ^1.9.0
  - firebase_ui_oauth ^1.4.15
  - firebase_ui_shared ^1.4.1
  - flutter any
  - flutter_localizations any
  - meta ^1.10.0
- firebase_auth 4.15.3
  - firebase_auth_platform_interface ^7.0.9
  - firebase_auth_web ^5.8.12
  - firebase_core ^2.24.2
  - firebase_core_platform_interface ^5.0.0
  - flutter any
  - meta ^1.8.0
- google_sign_in 6.2.1
  - flutter any
  - google_sign_in_android ^6.1.0
  - google_sign_in_ios ^5.7.0
  - google_sign_in_platform_interface ^2.4.0
  - google_sign_in_web ^0.12.0
- firebase_ui_oauth_google 1.2.15
  - firebase_auth ^4.15.0
  - firebase_ui_oauth ^1.4.15
  - flutter any
  - google_sign_in ^6.1.6
- flutter_riverpod 2.4.9
  - collection ^1.15.0
  - flutter any
  - meta ^1.4.0
  - riverpod 2.4.9
  - state_notifier >=0.7.2 <2.0.0

dev dependencies:
- flutter_test 0.0.0
  - flutter any
  - test_api 0.6.1
  - matcher 0.12.16
  - path 1.8.3
  - fake_async 1.3.1
  - clock 1.1.1
  - stack_trace 1.11.1
  - vector_math 2.1.4
  - async 2.11.0
  - boolean_selector 2.1.1
  - characters 1.3.0
  - collection 1.18.0
  - material_color_utilities 0.5.0
  - meta 1.10.0
  - source_span 1.10.0
  - stream_channel 2.1.2
  - string_scanner 1.2.0
  - term_glyph 1.2.1
  - web 0.3.0
- flutter_lints 3.0.1
  - lints ^3.0.0

transitive dependencies:
- _flutterfire_internals 1.3.16
  - collection ^1.0.0
  - firebase_core ^2.24.2
  - firebase_core_platform_interface ^5.0.0
  - flutter any
  - meta ^1.8.0
- args 2.4.2
- async 2.11.0
  - collection ^1.15.0
  - meta ^1.1.7
- boolean_selector 2.1.1
  - source_span ^1.8.0
  - string_scanner ^1.1.0
- characters 1.3.0
- clock 1.1.1
- collection 1.18.0
- crypto 3.0.3
  - typed_data ^1.3.0
- desktop_webview_auth 0.0.14
  - crypto ^3.0.3
  - flutter any
  - http ^1.0.0
  - flutter_web_plugins any
  - plugin_platform_interface ^2.1.4
- email_validator 2.1.17
- fake_async 1.3.1
  - clock ^1.1.0
  - collection ^1.15.0
- firebase_auth_platform_interface 7.0.9
  - _flutterfire_internals ^1.3.16
  - collection ^1.16.0
  - firebase_core ^2.24.2
  - flutter any
  - meta ^1.8.0
  - plugin_platform_interface ^2.1.3
- firebase_auth_web 5.8.12
  - firebase_auth_platform_interface ^7.0.9
  - firebase_core ^2.24.2
  - firebase_core_web ^2.10.0
  - flutter any
  - flutter_web_plugins any
  - http_parser ^4.0.0
  - js ^0.6.3
  - meta ^1.8.0
- firebase_core_platform_interface 5.0.0
  - collection ^1.0.0
  - flutter any
  - flutter_test any
  - meta ^1.8.0
  - plugin_platform_interface ^2.1.3
- firebase_core_web 2.10.0
  - firebase_core_platform_interface ^5.0.0
  - flutter any
  - flutter_web_plugins any
  - js ^0.6.3
  - meta ^1.8.0
- firebase_dynamic_links 5.4.8
  - firebase_core ^2.24.2
  - firebase_core_platform_interface ^5.0.0
  - firebase_dynamic_links_platform_interface ^0.2.6+16
  - flutter any
  - meta ^1.8.0
  - plugin_platform_interface ^2.1.3
- firebase_dynamic_links_platform_interface 0.2.6+16
  - _flutterfire_internals ^1.3.16
  - firebase_core ^2.24.2
  - flutter any
  - meta ^1.8.0
  - plugin_platform_interface ^2.1.3
- firebase_ui_localizations 1.9.0
  - flutter any
  - flutter_localizations any
  - path ^1.8.3
- firebase_ui_oauth 1.4.15
  - desktop_webview_auth ^0.0.14
  - firebase_auth ^4.15.0
  - firebase_ui_auth ^1.11.0
  - firebase_ui_shared ^1.4.1
  - flutter_svg ^2.0.9
  - flutter any
- firebase_ui_shared 1.4.1
  - flutter any
- flutter_localizations 0.0.0
  - flutter any
  - intl 0.18.1
  - characters 1.3.0
  - clock 1.1.1
  - collection 1.18.0
  - material_color_utilities 0.5.0
  - meta 1.10.0
  - path 1.8.3
  - vector_math 2.1.4
  - web 0.3.0
- flutter_web_plugins 0.0.0
  - flutter any
  - characters 1.3.0
  - collection 1.18.0
  - material_color_utilities 0.5.0
  - meta 1.10.0
  - vector_math 2.1.4
  - web 0.3.0
- google_identity_services_web 0.3.0+2
  - meta ^1.3.0
  - web >=0.3.0 <0.5.0
- google_sign_in_android 6.1.20
  - flutter any
  - google_sign_in_platform_interface ^2.2.0
- google_sign_in_ios 5.7.1
  - flutter any
  - google_sign_in_platform_interface ^2.2.0
- google_sign_in_platform_interface 2.4.3
  - flutter any
  - plugin_platform_interface ^2.1.0
- google_sign_in_web 0.12.3+1
  - flutter any
  - flutter_web_plugins any
  - google_identity_services_web ^0.3.0
  - google_sign_in_platform_interface ^2.4.0
  - http >=0.13.0 <2.0.0
  - web >=0.3.0 <0.5.0
- http 1.1.2
  - async ^2.5.0
  - http_parser ^4.0.0
  - meta ^1.3.0
  - web >=0.3.0 <0.5.0
- http_parser 4.0.2
  - collection ^1.15.0
  - source_span ^1.8.0
  - string_scanner ^1.1.0
  - typed_data ^1.3.0
- intl 0.18.1
  - clock ^1.1.0
  - meta ^1.0.2
  - path ^1.8.0
- js 0.6.7
  - meta ^1.7.0
- lints 3.0.0
- matcher 0.12.16
  - async ^2.10.0
  - meta ^1.8.0
  - stack_trace ^1.10.0
  - term_glyph ^1.2.0
  - test_api >=0.5.0 <0.7.0
- material_color_utilities 0.5.0
  - collection ^1.15.0
- meta 1.10.0
- path 1.8.3
- path_parsing 1.0.1
  - vector_math ^2.1.0
  - meta ^1.3.0
- petitparser 6.0.2
  - meta ^1.9.0
- plugin_platform_interface 2.1.7
  - meta ^1.3.0
- riverpod 2.4.9
  - meta ^1.9.0
  - stack_trace ^1.10.0
  - state_notifier >=0.7.2 <2.0.0
- sky_engine 0.0.99
- source_span 1.10.0
  - collection ^1.15.0
  - path ^1.8.0
  - term_glyph ^1.2.0
- stack_trace 1.11.1
  - path ^1.8.0
- state_notifier 1.0.0
  - meta ^1.1.8
- stream_channel 2.1.2
  - async ^2.5.0
- string_scanner 1.2.0
  - source_span ^1.8.0
- term_glyph 1.2.1
- test_api 0.6.1
  - async ^2.5.0
  - boolean_selector ^2.1.0
  - collection ^1.15.0
  - meta ^1.3.0
  - source_span ^1.8.0
  - stack_trace ^1.10.0
  - stream_channel ^2.1.0
  - string_scanner ^1.1.0
  - term_glyph ^1.2.0
- typed_data 1.3.2
  - collection ^1.15.0
- vector_graphics 1.1.9+1
  - flutter any
  - vector_graphics_codec 1.1.9+1
- vector_graphics_codec 1.1.9+1
- vector_graphics_compiler 1.1.9+1
  - args ^2.3.0
  - meta ^1.7.0
  - path_parsing ^1.0.1
  - xml ^6.3.0
  - vector_graphics_codec 1.1.9+1
  - path ^1.8.0
- vector_math 2.1.4
- web 0.3.0
- xml 6.5.0
  - collection ^1.18.0
  - meta ^1.9.0
  - petitparser ^6.0.0

Steps to reproduce

Steps to Reproduce:

  1. Log in with an unverified email account.
    AuthStateChangeAction<SignedIn>(
          (context, state) {
            if (!state.user!.emailVerified) {
              Navigator.pushNamed(context, RouteName.verifyEmail);
            }
          },
        ),
  2. Navigate to the email verification page.
  3. Verify the email.

    
    class EmailConfirmScreen extends StatelessWidget {
    const EmailConfirmScreen({
    super.key,
    });
    
    @override
    Widget build(BuildContext context) {
    return EmailVerificationScreen(
      actions: [
        EmailVerifiedAction(
          () {
            debugPrint('EmailVerifiedAction called');
    
            Navigator.pushReplacementNamed(context, RouteName.authGate);
          },
        ),
        AuthCancelledAction(
          (context) {
            Navigator.pop(context);
          },
        )
      ],
    );
    }
    }

4. Despite email verification, the loading icon still appears.

### Expected Behavior

Should trigger EmailVerifiedAction callback or show some UI to trigger it

### Actual Behavior

infinity loading indicator

### Additional Information

![image](https://github.com/firebase/FirebaseUI-Flutter/assets/90593296/9b597ed0-2b16-49a8-84c6-2175ded03969)
![image](https://github.com/firebase/FirebaseUI-Flutter/assets/90593296/6c613994-ccb3-4514-8cd0-0793616e1598)
danagbemava-nc commented 6 months ago

Hi @Trung15010802, Do you experience this same issue with the plugin example app?

I just ran the plugin example app and when I verified the email and returned to the app, I was directed to the profile page.

Trung15010802 commented 6 months ago

Hi @Trung15010802, Do you experience this same issue with the plugin example app?

I just ran the plugin example app and when I verified the email and returned to the app, I was directed to the profile page.

I did almost the same as the example app but I didn't use actionCodeSettings. Does that make a difference? As i know, the dynamic link will not available after 2025 so i didn't use it

tahamaddam commented 6 months ago

I experienced the same issue. A workaround is to develop your own email verification screen using StreamBuilder that listens to FirebaseAuth.instance.userChanges() stream. As soon as the email is verified (snapshot.data!.emailVerified), you can navigate the user to your desired location in the app.

danagbemava-nc commented 6 months ago

I did almost the same as the example app but I didn't use actionCodeSettings. Does that make a difference?

I don't think it should, does it work if you configure actionCodeSettings?

Trung15010802 commented 6 months ago

I experienced the same issue. A workaround is to develop your own email verification screen using StreamBuilder that listens to FirebaseAuth.instance.userChanges() stream. As soon as the email is verified (snapshot.data!.emailVerified), you can navigate the user to your desired location in the app.

Events are fired when the following occurs:

tahamaddam commented 6 months ago

When there is a change in the current user's token.

More on this here

danagbemava-nc commented 6 months ago

Hi @Trung15010802, if you configure your AuthStateChangeAction like below, does it work?

AuthStateChangeAction((context, state) {
                final user = switch (state) {
                  SignedIn(user: final user) => user,
                  CredentialLinked(user: final user) => user,
                  UserCreated(credential: final cred) => cred.user,
                  _ => null,
                };

                switch (user) {
                  case User(emailVerified: true):
                    Navigator.pushReplacementNamed(context, '/profile');
                  case User(emailVerified: false, email: final String _):
                    Navigator.pushNamed(context, '/verify-email');
                }
              }),
Trung15010802 commented 6 months ago

Hi @Trung15010802, if you configure your AuthStateChangeAction like below, does it work?

AuthStateChangeAction((context, state) {
                final user = switch (state) {
                  SignedIn(user: final user) => user,
                  CredentialLinked(user: final user) => user,
                  UserCreated(credential: final cred) => cred.user,
                  _ => null,
                };

                switch (user) {
                  case User(emailVerified: true):
                    Navigator.pushReplacementNamed(context, '/profile');
                  case User(emailVerified: false, email: final String _):
                    Navigator.pushNamed(context, '/verify-email');
                }
              }),

Thank you for your support. But it's doesn't work for me.

danagbemava-nc commented 6 months ago

Hi @Trung15010802, could you please provide a complete minimal reproducible code sample in a repo that we can clone so that we can investigate this?

Thank you

Trung15010802 commented 6 months ago

Hi @danagbemava-nc
Here is my source code. Very simple lib.zip

danagbemava-nc commented 6 months ago

Hi @tahamaddam, using your code sample, after returning to the app from verifying my email, the app properly redirects me to the home page.

How is your firebase project configured?

tahamaddam commented 6 months ago

Hi @tahamaddam, using your code sample, after returning to the app from verifying my email, the app properly redirects me to the home page.

How is your firebase project configured?

Was this message for me? @danagbemava-nc

utsavDave97 commented 6 months ago

Facing similar issue in iOS and I am running example code btw. ezgif com-video-to-gif-converter

danagbemava-nc commented 5 months ago

Was this message for me? @danagbemava-nc

Sorry @tahamaddam, it was for @Trung15010802

@utsavDave97, can you test on a physical device to see if you still get this issue?

Trung15010802 commented 5 months ago

Was this message for me? @danagbemava-nc

Sorry @tahamaddam, it was for @Trung15010802

@utsavDave97, can you test on a physical device to see if you still get this issue?

Yes i have already tested in real device. I configure firebase like this tutorial https://firebase.google.com/docs/flutter/setup?hl=vi&platform=ios

danagbemava-nc commented 5 months ago

Labeling for further investigation as I cannot reproduce this locally

cc @lesnitsky, maybe you can offer some insight as to why this is happening

stact commented 5 months ago

Does this method will still work after Firebase Dynamic Links deprecation in August 2025? Maybe this part must be reviewed / refactored.

ActionCodeSettings has no more sense.

https://firebase.google.com/support/dynamic-links-faq

FYI @danagbemava-nc

stact commented 5 months ago

Working on my side too, maybe it's something related to Firebase config, did you put the right SHA related to your build on Firebase?

timeuser commented 5 months ago

In my case, if you don't leave the app the verification never happens. You have to leave the app and re-open it.

Example:

  1. Register a new account
  2. Email verification screen comes up showing spinner and waiting for verification
  3. I check email on my laptop and verify the email address
  4. Email verification screen still just sits there on my phone spinning indefinitely
  5. I exit the app and re-open it and verification screen closes

Perhaps this isn't a common flow a real user would go through as they would check their email from the same device. But as a developer building on a simulator or test devices I don't necessarily have email access on the same device. This is the most likely flow I hit the first time I tried and it took me a while to realize what was going on.

KunalNestFuel commented 3 months ago

Hi , I am facing the same issue while using web version in mobile chrome.