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.63k stars 3.95k forks source link

[firebase_dynamic_links] App in background restart on auth link open (Android) #2250

Closed tzvc closed 3 years ago

tzvc commented 4 years ago

I'm trying to implement passwordless authentication with firebase_auth signin links by i'm running into an issue. When my app is running in the background and I click on the link in my email inbox and choose "Open with ", the app restarts completely and getInitialLink() returns null.

My link is generated like so

      FirebaseAuth.instance.sendSignInWithEmailLink(
          email: _email,
          androidInstallIfNotAvailable: true,
          iOSBundleID: "app.bar.foo",
          androidMinimumVersion: "16",
          androidPackageName: "app.bar.foo",
          url: "https://getfoo.app/verification/register",
          handleCodeInApp: true);

The weird thing is that if I just open https://getfoo.app/verification/register while my app is in background, it seems to work fine (not the authentication, but the app doesnt restart).

Any ideas?

Cheers! 😃

firebase_dynamic_links: ^0.5.0+11 firebase_auth: ^0.15.5+2

iapicca commented 4 years ago

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

tzvc commented 4 years ago

@iapicca here you go ;)

flutter doctor -v:

[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.14.5 18F132, locale en-AU)
    • Flutter version 1.12.13+hotfix.8 at /Users/theo/flutter
    • Framework revision 0b8abb4724 (7 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 28.0.3)
    • Android SDK at /Users/theo/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 28.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_152-release-1248-b01)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    ✗ Flutter requires a minimum Xcode version of 11.0.0.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.7.4

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] VS Code (version 1.42.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.8.1

[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

flutter run --verbose logs:

[   +1 ms] W/DynamiteModule(19383): Local module descriptor class for com.google.firebase.auth not found.
[        ] I/FirebaseAuth(19383): [FirebaseAuth:] Preparing to create service connection to gms implementation
[+17905 ms] D/DecorView(19383): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@52c9d32[MainActivity]
[+17586 ms] D/DecorView(19383): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@52c9d32[MainActivity]

// here I call the firebase_auth sendSignInEmail()

[ +890 ms] I/BiChannelGoogleApi(19383): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms:
com.google.firebase.auth.api.internal.zzaq@b2a1319

// here I put the app on background to open my gmail

[+9943 ms] D/FlutterView(19383): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@22d19ca
[+4353 ms] W/ActivityThread(19383): handleWindowVisibility: no activity for token android.os.BinderProxy@4435045

// the link open the app back

[  +22 ms] D/FlutterActivityAndFragmentDelegate(19383): Setting up FlutterEngine.
[        ] D/FlutterActivityAndFragmentDelegate(19383): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this
FlutterFragment.
[ +266 ms] D/FlutterActivityAndFragmentDelegate(19383): Attaching FlutterEngine to the Activity that owns this Fragment.
[ +218 ms] D/FlutterView(19383): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@5f58181
[   +6 ms] D/FlutterActivityAndFragmentDelegate(19383): Executing Dart entrypoint: main, and sending initial route: /
[  +11 ms] D/DecorView(19383): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@ac8ea03[MainActivity]

my pubspec.yml:

dependencies:
  google_sign_in: ^4.0.0
  firebase_auth: ^0.15.5+2
  cloud_functions: ^0.4.1+6
  cloud_firestore: ^0.12.7
  geoflutterfire: ^2.0.3+5
  image_picker: ^0.5.0+3
  firebase_storage: ^3.0.1
  timeago: ^2.0.10
  geolocator: ^5.3.0
  google_maps_flutter: ^0.5.21+6
  cached_network_image: ^1.1.1
  firebase_messaging: ^5.1.8
  geocoder: ^0.2.1
  image: ^2.0.7
  provider: ^3.1.0
  fluster: ^1.1.2
  overlay_support: ^1.0.1
  responsive_image: ^0.1.0
  intl: ^0.16.1
  firebase_dynamic_links: ^0.5.0+11
  package_info: ^0.4.0+16
  flutter_secure_storage: ^3.3.1+1
  flutter_facebook_login: ^3.0.0
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_launcher_icons: '^0.7.0'
  flutter_test:
    sdk: flutter
russellwheatley commented 3 years ago

Hey @theochampion, getInitialLink isn't guaranteed to return the link data, you should also make use of onLink api to get the link data should getInitialLink return null.