FiresoreSettings with SSR causes No Firebase App '[DEFAULT]' has been created
misomarcell opened this issue · 1 comments
In my Angular app I have 3 configuration files: 1 for common providers, 1 for server and 1 for client. I'm initializing Firestore in the common one, like this:
provideFirestore(() => {
const firestore = initializeFirestore(inject(FirebaseApp), {
ignoreUndefinedProperties: true,
localCache: memoryLocalCache()
});
if (!environment.production) {
connectFirestoreEmulator(firestore, "localhost", 8080);
}
return firestore;
}),
While on the client it works just fine, my server app throws errors on each reload, saying:
_FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).
In the client config I'M initializing the app with provideFirebaseApp(() => initializeApp(environment.firebase)) while for the server, I use
provideFirebaseApp(() => {
const requestContext = inject(REQUEST_CONTEXT, { optional: true }) as
| {
authIdToken: string;
}
| undefined;
const authIdToken = requestContext?.authIdToken;
return initializeServerApp(environment.firebase, { authIdToken });
})
I've tried switching the order of providers, using getFirestore() instead, using getApp() instead, but nothing seem to work. Previously when I was still using zone.js, the error didn't cause the app to stop and were complaining about my setting of ignoreUndefinedProperties: true inside the initializeFirestore() I use this setting extensively, so getting rid of it is not an option.
Versions:
"@angular/common": "^19.1.0",
"@angular/fire": "^19.0.0",
"firebase": "^11.3.1",
This issue does not seem to follow the issue template. Make sure you provide all the required information.