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

[FIREBASE_AUTH] Unable to send verification email a second time right after registration #2054

Closed miles-au closed 4 years ago

miles-au commented 4 years ago

Describe the bug I'm creating a Flutter App that uses Firebase for authentication.

Upon registration, the user is sent a verification email. The user is then shown a screen to let them know that an email was sent to them. I'd like to include a button on this screen where they can send a second email in case they missed the first one somehow.

I'm finding that the second time I try sending the email, there's no response and leaves the asynchronous function hanging. I've tried simply calling user.sendEmailVerification() twice after registration, and it seems that it will only send one email. As soon as I do a hot reload though, it seems there are no more problems sending the verification email, and I can send the email more than once.

I'm thinking maybe this has something to do with Firebase trying to prevent multiple copies of the same request? Was wondering if anyone knows for sure or has experienced this.

Additional context


// code to create user and send email
  final authResult = await _instance.createUserWithEmailAndPassword(
      email: email, password: password);
  if (authResult != null) {
    await authResult.user.sendEmailVerification();
    await _instance.signOut();
    return Response(
        status: Status.success,
        message:
            'Successfully created account. Awaiting email verification.',
        body: authResult.user);
  }

// button press function on the email verification screen
                  onPressed: () async {
                    print('attempting to send verification email');
                    try {
                      await user.sendEmailVerification();
                      print("sent");
                      CustomAlertDialog.messageAlertDialog(
                        context,
                        'Verification email sent',
                        '',
                        "Continue",
                      );
                    } catch (error) {
                      print("error sending verification error: $error");
                      CustomAlertDialog.messageAlertDialog(
                        context,
                        'Verification email failed',
                        error,
                        "Continue",
                      );
                    }
                  }
iapicca commented 4 years ago

Hi @miles-au can you please provide your flutter doctor -v , your flutter run --verbose and your pubspec.yaml Thank you

miles-au commented 4 years ago

Hey @iapicca , thanks for checking in!

flutter doctor -v

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.2 19C57, locale en-CA)
    • Flutter version 1.12.13+hotfix.8 at /Users/milesau/flutter
    • Framework revision 0b8abb4724 (4 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/milesau/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • ANDROID_HOME = /Users/milesau/Library/Android/sdk
    • 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.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 44.0.2
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] Connected device (1 available)
    • Miles' iPhone • ac6c5ef2579398775deb3143564346ed43c9848b • ios • iOS 13.1.3

• No issues found!

flutter run --verbose

[        ] flutter: user: FirebaseUser(Instance of 'PlatformUser')
[        ] flutter: email: miles.au@live.ca
[  +56 ms] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817927467, bytes: Zmx1dHRlcjogYnVpbGQgbG9naW4gc2NyZWVu}}
[   +1 ms] flutter: build login screen
[        ] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817927468, bytes: Cg==}}
[ +247 ms] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817927716, bytes: Zmx1dHRlcjogYnVpbGQgbG9naW4gc2NyZWVu}}
[   +1 ms] flutter: build login screen
[        ] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817927716, bytes: Cg==}}
[+33403 ms] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817961121, bytes: Zmx1dHRlcjogYXR0ZW1wdGluZyB0byBzZW5kIHZlcmlmaWNhdGlvbiBlbWFpbA==}}
[   +1 ms] flutter: attempting to send verification email
[        ] Notification from VM: {streamId: Stdout, event: {type: Event, kind: WriteEvent, isolate: {type: @Isolate, id: isolates/4202632943994099, name: main, number: 4202632943994099}, timestamp:
1583817961121, bytes: Cg==}}

pubspec.yaml


version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  arcore_flutter_plugin:
    git:
      url: git://github.com/miles-au/arcore_flutter_plugin.git
      ref: master

  arkit_plugin: ^0.3.0
  camera: ^0.5.7+3
  path_provider: ^1.6.0
  path: ^1.6.4
  flutter_image_compress: ^0.6.5+1
  gallery_saver: ^1.0.7
  multi_image_picker: ^4.6.1
  firebase_core: ^0.4.3+3
  firebase_auth: ^0.15.3
  cloud_firestore: ^0.13.1
  platform_alert_dialog: ^1.0.0+2
  network_image_to_byte: ^0.0.1
  firebase_storage: ^3.1.1
  bloc: ^3.0.0
  flutter_bloc: ^3.2.0
  palette_generator: ^0.2.2
  tflite: ^1.0.5
  image: ^2.1.4

dev_dependencies:
  flutter_test:
    sdk: flutter

edit: formatting

miles-au commented 4 years ago

It was a problem on my part, user needs to be logged in to be able to send verification emails. Users weren't signed in after registration, but would be signed in when I went through the log in screen. Closing the issue, thanks @iapicca for checking it out!