我创建了一个 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
文件,但错误仍然存在。
您有什么想法可以解决这个问题吗?
可能是因为你没有添加认证持久化。请看看这是否有帮助:
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,
indexedDBLocalPersistence
} from '@angular/fire/auth'; // **<-- Import**
import { environment } from 'src/environments/environment.prod';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
provideAuth(() => { **// <-- Use**
const auth = getAuth();
auth.setPersistence(indexedDBLocalPersistence);
return auth;
}),
],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}