简体   繁体   中英

flutter + firebase passwordless email login - dynamic link data returns null

I am trying to implement passwordless email login on my app. After the link has been clicked on, the app returns from the background but the dynamic link is null.

This is how I send the mail (with the right values for my app of course):

user.sendSignInWithEmailLink(
      email: _email,
      androidInstallIfNotAvailable: true,
      iOSBundleID: "com.company.appname",
      androidMinimumVersion: "16",
      androidPackageName: "com.company.appname",
      url: "https://appname.page.link/email",
      handleCodeInApp: true);

I also added the intent as follows:

<intent-filter>
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.BROWSABLE" />

           <data android:host="appname.page.link" android:scheme="http"/>
           <data android:host="appname.page.link" android:scheme="https"/>
        </intent-filter>

Tried different variations with the intent, and non helped, including writing the firebase project url as the host like: project-name.firebaseapp.com

The data still comes back empty.

Any thoughts? am I missing something?

I've updated the firebase_dynamic_links package to the latest version (0.5.0+9), while using the configuration below and it starts working.

Sending sign-in link configuration:

firebaseAuth.sendSignInWithEmailLink(
        email: email,
        url: "https://mydemoapp.page.link/email",
        androidInstallIfNotAvailable: true,
        androidMinimumVersion: '21',
        androidPackageName: 'com.example.mydemoapp'
        handleCodeInApp: true,
        iOSBundleID: 'com.example.mydemoapp');

AndroidManifest.xml intent-filter configuration:

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <intent-filter>
        <data android:host="mydemoapp.page.link" android:scheme="https"/>
        <data android:host="mydemoapp.page.link" android:scheme="http"/>
    </intent-filter>

Getting a dynamic link in Flutter.

The example comes form from https://pub.dev/packages/firebase_dynamic_links

If your app did not open from a dynamic link, getInitialLink() will return null . That's the reason why you have to FirebaseDynamicLinks.instance.onLink implemented in case the app is already opened.

void main() {
  runApp(MaterialApp(
    title: 'Dynamic Links Example',
    routes: <String, WidgetBuilder>{
      '/': (BuildContext context) => MyHomeWidget(), // Default home route
      '/helloworld': (BuildContext context) => MyHelloWorldWidget(),
    },
  ));
}

class MyHomeWidgetState extends State<MyHomeWidget> {
  .
  .
  .
  @override
  void initState() {
    super.initState();
    this.initDynamicLinks();
  }

  void initDynamicLinks() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
      Navigator.pushNamed(context, deepLink.path);
    }

    FirebaseDynamicLinks.instance.onLink(
      onSuccess: (PendingDynamicLinkData dynamicLink) async {
        final Uri deepLink = dynamicLink?.link;

        if (deepLink != null) {
          Navigator.pushNamed(context, deepLink.path);
        }
      },
      onError: (OnLinkErrorException e) async {
        print('onLinkError');
        print(e.message);
      }
    );
  }
  .
  .
  .
}

The mydemoapp.page.link must be added to Authorized domains in Firebase console

appname.page.link还是appname.page.link/email您只需指定一封电子邮件即可实现

If coming to this answer in March 2022, this error is happening again and it's a bug on Flutterfire.

Here is the issue with a Pull Request that hasn't been merged yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM