I created an Ionic 5 + Capacitor + Firebase project and added the latest version of AngularFire to it.
Everything works perfectly on Desktop but when I launch on my iPhone, there is an error (Well, there is no error but the redirection of my first page does not work).
So, no error in the logs but a white screen.
After much research, I came to the following conclusion.
I use AngularFireAuthGuard as follows :
{
path: '',
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule),
...canActivate(() => redirectUnauthorizedTo(['landing']))
}
And my research made me realize that with latest version of AngularFire firebase Auth is not detected properly.
So I found a piece of code that solved the problem for me for a while :
import { Component } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { initializeApp } from 'firebase/app';
import { indexedDBLocalPersistence, initializeAuth } from 'firebase/auth';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
constructor() {
const app = initializeApp(environment.firebase);
if (Capacitor.isNativePlatform) {
initializeAuth(app, {
persistence: indexedDBLocalPersistence
});
}
}
}
As soon as I wanted to add the onAuthStateChanged in my app.component I got the following error :
auth/already-initialized
In my opinion, it might be because my app.module.ts looks like this :
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
IonicStorageModule.forRoot(),
AppRoutingModule,
AngularFireAuthModule,
AngularFireModule.initializeApp(environment.firebase)
],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
My application is initialized here but if I delete it I get another injection error...
Do you have any ideas how I can fix the problem ?