You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase无密码邮箱认证功能故障求助

Firebase无密码邮箱认证Deep Link配置故障求助

背景

耗时3天调试Firebase无密码邮箱认证,始终卡在Deep Link配置环节,查阅官方文档、YouTube教程及各类论坛均未解决。官方文档表述模糊且更新频繁,部分内容已过时;因SafetyNet停用,原OTP认证系统无法正常工作,只能转向无密码邮箱认证方案。

已完成的配置与尝试

  • 配置自定义域名,添加对应DNS记录及.well-known文件夹下的JSON验证文件
  • 将域名加入Firebase控制台的authorizedDomainLists
  • 修改AndroidManifest中的intent-filter:
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <!-- If a user clicks on a shared link that uses "http" scheme, 
        the app should be able to delegate that traffic to "https". -->
    <data android:scheme="http" />
    <data android:scheme="https" />

    <!-- Include one or more domains that should be verified. -->
    <data android:host="example.page.link" />
</intent-filter>
  • 引入Dynamic Links所需SDK
  • 实现sendEmailLink方法:
Future<AppResponse> sendEmailLink({required String email}) async {
  final actionCodeSettings = ActionCodeSettings(
    url: deepLinkPrefix,
    handleCodeInApp: true,
    androidPackageName: packageName,
    iOSBundleId: packageName,
  );
  await auth.sendSignInLinkToEmail(
    email: email,
    actionCodeSettings: actionCodeSettings,
  );
  return AppResponse.success(
    id: 'sendSignInLinkToEmail',
    message: 'Email link sent successfully',
  );
}

(注:AppResponse为教程中使用的弹窗组件)

  • 实现retrieveDynamicLinkAndSignIn方法,但该方法始终无法触发:
// fromColdState means if the app was closed
Future<AppResponse> retrieveDynamicLinkAndSignIn({required bool fromColdState}) async {
  try {
    PendingDynamicLinkData? dynamicLinkData;

    // Decide where to get link from if App is closed or not
    if (fromColdState) {
      dynamicLinkData = await FirebaseDynamicLinks.instance.getInitialLink();
    } else {
      dynamicLinkData = await FirebaseDynamicLinks.instance.onLink.first;
    }
    if (dynamicLinkData == null) {
      return AppResponse.notFound(
        id: 'retrieveDynamicLinkAndSignIn',
        message: 'No Credentials Found',
      );
    }

    // Check if link is valid
    bool validLink = auth.isSignInWithEmailLink(dynamicLinkData.link.toString());
    if (validLink) {
      // Get the users email address from the continueUrl
      final continueUrl = dynamicLinkData.link.queryParameters['continueUrl'] ?? '';
      final email = Uri.parse(continueUrl).queryParameters['email'] ?? '';

      // Use email to sign in with credentials
      final UserCredential userCredential = await auth.signInWithEmailLink(
        email: email,
        emailLink: dynamicLinkData.link.toString(),
      );

      // Check to make sure user credential is not null
      if (userCredential.user != null) {
        return AppResponse.success(
          id: 'signInWithEmailLink',
          message: 'Signed in successfully',
        );
      } else {
        return AppResponse.notFound(
          id: 'signInWithEmailLink',
          message: 'Not able to sign in',
        );
      }
    } else {
      return AppResponse.notFound(
        id: 'signInWithEmailLink',
        message: 'Link is not valid',
      );
    }
  } catch (e, s) {
    return AppResponse.error(
      id: 'signInWithEmailLink',
      error: e,
      stackTrace: s,
    );
  }
}
  • 尝试运行pub.dev上的Firebase Dynamic Links示例,但因在Main()中调用Navigator无上下文而无法正常运行

当前核心问题

  1. 点击邮件中的认证链接会直接跳转到Play商店(应用未发布),无法唤起已安装的本地应用
  2. 切换回Firebase默认Deep Link时,提示“无效URL,Dynamic Link被拦截”
  3. retrieveDynamicLinkAndSignIn方法完全无法触发,无法完成后续登录流程

内容的提问来源于stack exchange,提问作者Technorocker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 01:02:55