简体   繁体   中英

After the latest (august 2020) firebase update , Complete sign in with the email link has stopped working for flutter

This is my code

Future<bool> sendSignInWithEmailLink(email) async {
  final FirebaseAuth user = FirebaseAuth.instance;
  _email = email;

//  try {
//    user.sendSignInWithEmailLink(
//        email: email,
//        androidInstallIfNotAvailable: true,
//        iOSBundleID: kName, //constant
//        androidMinimumVersion: "16",
//        androidPackageName: kName, //constant
//        url: kLink, //constant
//        handleCodeInApp: true);
  try {
    user.sendSignInLinkToEmail(
      email: _email,
      actionCodeSettings: ActionCodeSettings(
          url: appEmail + _email,
          iOS: {"bundleId": kName},
          android: {
            "packageName": kName,
            "installApp": true,
            "minimumVersion": '12'
          },
          handleCodeInApp: true,
          dynamicLinkDomain: kLink),
    );
  } catch (e) {
    return false;
  }
  print(email + "<< sent");
  return true;
}

Future<void> getInitialLink() async {
  final PendingDynamicLinkData data =
      await FirebaseDynamicLinks.instance.getInitialLink();

  final Uri deepLink = data?.link;
  print(deepLink.toString());

  if (deepLink.toString() != null) {
    _link = deepLink.toString();
    _signInWithEmailAndLink();
  }
}

Future<void> _signInWithEmailAndLink() async {
  final FirebaseAuth user = FirebaseAuth.instance;
  bool validLink = await user.isSignInWithEmailLink(_link);
  if (validLink) {
    try {
      await user.signInWithEmailLink(email: _email, emailLink: _link);
    } catch (e) {
      print(e);
    }
  }
}

Before the update commented ( sendSignInWithEmailLink ) code would work fine. But after the update it no longer works and I tried using sendSignInLinkToEmail but could not make it work.

How can I make it to work again.

Worked for me:

            FirebaseAuth.instance.sendSignInLinkToEmail(
              email: "example@example.com",
              actionCodeSettings: ActionCodeSettings(
                url: "https://example.web.app",
                android: {
                  'packageName': "com.example.example",
                  'installApp': true,
                  'minimumVersion': '12'
                },
                iOS: {
                  'bundleId': "com.example.example",
                },
                handleCodeInApp: true,
              ),
            );

You need to check out the FlutterFire webpage. They have a migration page that goes over how to update your methods and objects to accommodate the new version. https://firebase.flutter.dev/docs/migration/

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