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

Firebase Phone Auth网页端正常但iOS设备报auth/internal-error错误

问题:Ionic 8 + Capacitor + Firebase iOS端启动出现auth/internal-error错误

我创建了一个Ionic 8 + Capacitor + Firebase项目,并集成了最新版本的AngularFire。网页端运行完全正常,但在iPhone上启动时,Xcode控制台出现错误:[error] - ERROR {"code":"auth/internal-error","customData":{},"name":"FirebaseError"}。

我的app.module.ts代码如下:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { environment } from 'src/environments/environment.prod';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule],
  providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
    provideAuth(() => getAuth())],
  bootstrap: [AppComponent],
})
export class AppModule {}

我已花费大量时间尝试多种方法但均无效,甚至在Xcode中安装了Firebase SDK(不确定是否必要),也配置了GoogleService-Info.plist文件,但错误仍存在。请问有什么解决思路吗?


解决思路

1. 配置Capacitor Firebase Auth插件

AngularFire在iOS原生端无法直接复用web逻辑,必须依赖@capacitor-firebase/auth插件处理原生认证流程:

  • 安装插件:npm install @capacitor-firebase/auth
  • 同步到iOS项目:npx cap sync ios
  • 确保GoogleService-Info.plist通过Xcode拖入项目根目录,勾选"Copy items if needed",避免仅存在于文件系统中

2. 核对Firebase与Xcode的应用配置

  • 登录Firebase控制台,确认iOS应用的Bundle ID与Xcode项目中的Bundle ID完全一致(大小写敏感)
  • 重新下载最新的GoogleService-Info.plist替换旧文件,避免配置信息过期

3. 调整AppModule的认证初始化逻辑

修改provideAuth的配置,针对原生平台使用专用的认证初始化方式,避免web端持久化策略冲突:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { initializeApp, provideFirebaseApp, getApp } from '@angular/fire/app';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { initializeAuth, indexedDBLocalPersistence } from 'firebase/auth';
import { Capacitor } from '@capacitor/core';
import { environment } from 'src/environments/environment.prod';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule],
  providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
    provideAuth(() => {
      if (Capacitor.isNativePlatform()) {
        return initializeAuth(getApp(), {
          persistence: indexedDBLocalPersistence
        });
      } else {
        return getAuth();
      }
    })],
  bootstrap: [AppComponent],
})
export class AppModule {}

4. 检查Xcode签名与权限

  • 确认Xcode项目的Team配置正确,签名证书有效且未过期
  • 若使用第三方登录(如Google),需在Info.plist中添加LSApplicationQueriesSchemes数组,包含对应登录的scheme(例如com.googleusercontent.apps.xxxxxx)
  • 确保iOS目标版本不低于13.0,满足Firebase SDK的最低要求

5. 清理重建项目

  • Xcode中执行Cmd+Shift+K清理项目,手动删除DerivedData文件夹(路径:~/Library/Developer/Xcode/DerivedData)
  • 清理npm依赖:rm -rf node_modules package-lock.json && npm install
  • 重新同步Capacitor:npx cap sync ios
  • 重新构建并运行项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 06:05:20