Flutterfire: [firebase_dynamic_links] Firebase auth sign in links don't trigger onLink

Created on 2 Apr 2020  Â·  6Comments  Â·  Source: FirebaseExtended/flutterfire

I'm using firebase_auth and firebase_dynamic_links to implement passwordless login.
When I click on the link in the auth email, it opens in my app as it should but the link isn't handled (the onLink callback is not called).

The weird thing is that every other dynamic links I have work properly (they get handled in onLink).

I extracted the link from the email, it looks like this:

https://getmyapp.app/?link=https://myapp-5p4rk.firebaseapp.com/__/auth/action?apiKey=AIzaSyCEMaEKrsNTUokeWrGjo-CnNLlRk1xjvhU&mode=signIn&oobCode=r2UXpa0FotRZjD2YzMEvxBhohCwrcsd3YR63MmxR4S4AAAFxO9QVVA&continueUrl=https://getmyapp.app/links/sign_in&lang=fr&apn=app.myapp.myapp&amv=21&ibi=app.myapp.myapp&ifl=https://myapp-5p4rk.firebaseapp.com/__/auth/action?apiKey=AIzaSyCEMaEKrsNTUokeWrGjo-CnNLlRk1xjvhU&mode=signIn&oobCode=r2UXpa0FotRZjD2YzMEvxBhohCwrcsd3YR63MmxR4S4AAAFxO9QVVA&continueUrl=https://getmyapp.app/links/sign_in&lang=fr

So, from what I understand, I call is made at https://myapp-5p4rk.firebaseapp.com/__/auth/action (i'm not sure why is that step needed) and then it gets redirected to my dynamic link I configured in the console https://getmyapp.app/links/sign_in. At this point, it should open my app and onLink should trigger. But it doesn't happen.

Now if I just enter https://getmyapp.app/links/sign_in in my browser, my app open and onLink is triggered!

I don't really what is the difference and what could cause the link coming from the email not to trigger onLink... Any ideas? 😄

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

The code I use for handling the links in my app:

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _initDynamicLinks();
  }

  _signInWithDynamicLink(Uri link) async {
    if (link == null) return;
    final bool isSignInLink =
        await FirebaseAuth.instance.isSignInWithEmailLink(link.toString());
    if (!isSignInLink) return;
    try {
      // await FirebaseAuth.instance
      //     .signInWithEmailAndLink(email: _email, link: link.toString());
    } catch (error) {
      return showSimpleNotification(Text("Invalid email link"),
          background: Colors.red, slideDismiss: true);
    }
  }

  void _initDynamicLinks() async {
    final PendingDynamicLinkData data =
        await FirebaseDynamicLinks.instance.getInitialLink();

    _signInWithDynamicLink(data?.link);

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
      _signInWithDynamicLink(dynamicLink?.link);
    }, onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    });
  }
crowd dynamic_links bug documentation

Most helpful comment

Im having the same issue,the app open but the callback onLink don't trigger

All 6 comments

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

Possible duplicate of #2221

Hi @TahaTesser,

I don't think this is a duplicate of https://github.com/FirebaseExtended/flutterfire/issues/2221 as I am having the issue on Android (dont have an Iphone to test on) and I'm not using the page.link host (I'm using a custom host).

Related to that, when I try to use the default host myapp.page.link in firebase, I get an error:

Screen Shot 2020-04-02 at 8 08 00 pm

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

Any updates on this? Anyone having the same issue?

Im having the same issue,the app open but the callback onLink don't trigger

Same issue here, but happening only with _some_ iOS devices. _Some_ iOS logins works just fine.

Update: this might be related to this firebase-ios-sdk issue, which also mentions a related issue on Apple Developer Forum.

My app correctly detects dynamic links I create and I'm able to handle them (both initial links and when onLink is triggered). This is on both Android and iOS devices. However, as the original post points out, the links sent in emails by firebase_auth are not detected for some reason. So if a user gets an email confirmation or password reset email and taps on it while holding a mobile device, it will open the mobile app but nothing happens (as far as I can see, and I just updated firebase_dynamic_links to make sure). So I'm not sure if the problem is with firebase_auth or with firebase_dynamic_links (perhaps the latter is filtering those somehow). Note that when the emails are sent by Firebase Auth, I have them correctly using my custom domain.

Not sure if we're supposed to explicitly set dynamicLinks: false for the /__/auth path in our firebase.json at the root of our domain or what - something like this which I haven't tried yet:

{
  "hosting": {
    "appAssociation": "AUTO",
    "rewrites": [
      { 
        "source": "/__/auth**", 
        "dynamicLinks": false 
      },

I'm wondering if the only way to have a decent UX with Flutter at the moment is to trigger a cloud function that uses the Firebase Admin SDK so that it can make use of generatePasswordResetLink which is not available on the client side. Then maybe passing ActionCodeSettings would allow me to force the link to be opened in a web browser instead of the mobile app.

But ideally the Firebase SDKs for Flutter would give us a parameter to tell it to send a password reset email that opens in a web browser only. That or help us figure out how to read these links in the mobile app. :)

Was this page helpful?
0 / 5 - 0 ratings