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

Firebase Auth的sendSignInLinkToEmail方法触发内部错误求助

Firebase Auth发送邮箱登录链接抛出[firebase_auth/internal-error]内部错误的解决方案

问题概述

尝试通过Firebase Auth实现邮箱链接登录功能,调用sendSignInLinkToEmail方法时触发模糊的[firebase_auth/internal-error]内部错误,无法获取具体错误详情。当前Google Sign-In功能正常,可排除Firebase基础配置问题。

已完成的配置

  • 在Firebase控制台开启邮箱链接登录方式
  • 将回调URL添加到授权域名白名单

原始实现代码

@override
Future<String> signInWithEmail(String email) async {
  var acs = ActionCodeSettings(
    url: 'https://myweb.app',// 使用真实URL
    handleCodeInApp: true,
    iOSBundleId: 'com.company.app', // 使用真实iOSBundleId
    // androidPackageName: 'com.example.android',
    // androidInstallApp: true,
    // androidMinimumVersion: '12'
  );
  await logout();
  log('after logout: ${auth.currentUser}');
  return await auth.sendSignInLinkToEmail(email: email, actionCodeSettings: acs).then((value) {
    log('Successfully sent email verification');
    return 'Successfully sent email verification';
  }).catchError((e) {
    log('Error 21: ${e}');
    return 'Error sending email verification $e';
  });
}

2023-8-12更新:问题复现

已在全新环境中复现问题,步骤如下:

  1. 创建全新Firebase项目
  2. 创建全新Flutter项目
  3. 通过CLI完成Flutter的Firebase配置
  4. 在Firebase控制台开启邮箱链接登录
  5. 将域名添加到授权域名白名单
  6. 使用最小复现代码测试

复现代码

import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform).whenComplete(() {
    print("completedAppInitialize");
  });
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  Future signup() async {
    var acs = ActionCodeSettings(
      url: 'https://domain.app/finishSignUp?cartId=1234',
      handleCodeInApp: true,
      iOSBundleId: 'com.example.exp1',
      // androidPackageName: 'com.example.android',
      // androidInstallApp: true,
      // androidMinimumVersion: '12'
    );

    var emailAuth = 'name@gmail.com';
    FirebaseAuth.instance
        .sendSignInLinkToEmail(email: emailAuth, actionCodeSettings: acs)
        .catchError((onError) => print('Error sending email verification $onError'))
        .then((value) => print('Successfully sent email verification'));

    return;
  }

  @override
  void initState() {
    super.initState();
    signup();
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text('Hello World!'),
        ),
      ),
    );
  }
}

控制台输出

flutter: completedAppInitialize
flutter: Error sending email verification [firebase_auth/internal-error] An internal error has occurred, print and inspect the error details for more information.
flutter: Successfully sent email verification

排查与解决建议

1. 校验ActionCodeSettings配置

  • 确保url对应的根域名(如https://domain.app)已完整添加到Firebase授权域名列表,无需包含路径参数;
  • iOSBundleId必须与Xcode项目中的Bundle Identifier完全一致,大小写敏感;
  • 若暂不支持Android平台,直接删除相关配置代码,不要保留注释后的空参数,避免触发内部校验逻辑冲突。

2. 开启调试日志获取详情

在Firebase初始化后添加日志配置,获取更详细的错误堆栈:

FirebaseAuth.instance.setLogLevel(LogLevel.debug);

调试日志会输出内部错误的具体原因,帮助定位问题。

3. 检查邮箱与发送限制

  • 确保测试邮箱格式正确,无特殊字符;
  • 若短时间内多次测试,可能触发Firebase的反垃圾邮件机制,更换测试邮箱或等待一段时间后重试。

4. 验证OAuth与项目配置

  • 进入Firebase控制台「Authentication」-「设置」-「授权域名」,确认回调URL的域名已正确添加;
  • 检查iOS端GoogleService-Info.plist中的BUNDLE_ID、CLIENT_ID是否与Firebase控制台配置完全匹配。

5. 更新FlutterFire插件

执行命令更新firebase_auth到最新稳定版,旧版本可能存在已知bug:

flutter pub upgrade firebase_auth

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 05:30:13