Description
Reproduction
https://github.com/aaaaahaaaaa/vuefire-bug-170924
Steps to reproduce the bug
My knowledge of Vue and Nuxt plugins is somewhat limited, but it seems to me that there is a bug with regards to the initialisation of the FirebaseApp
server side (at least in middlewares). Yes, the features related to Firebase Auth shown in the documentation work (e.g. getCurrentUser
), but not using Firestore.
Example, simply getting the Firestore instance in a middleware (SSR enabled):
import { useFirestore } from "vuefire"
export default defineNuxtRouteMiddleware(async (to, from) => {
const db = useFirestore()
})
Throws the typical error:
No Firebase App [DEFAULT] has been created - call initializeApp() first
It's reproduced on the test repo here. Only the config and the service account need to be added.
When accessing directly the firebaseApp
provided by the plugin itself as a helper here, it does work:
export default defineNuxtRouteMiddleware(async (to, from) => {
const { $firebaseApp } = useNuxtApp()
const db = getFirestore($firebaseApp)
const user = await getCurrentUser($firebaseApp.name)
const userDoc = await getDoc(doc(db, `users/${user.uid}`))
...
})
And yes, my Firebase app returned here is still [DEFAULT]
.
Expected behavior
I would expect the Firestore utility functions and composables to work out of the box, i.e. the FirebaseApp to be initialized, in the context of server-side middlewares.
Actual behavior
FirebaseApp isn't initialized
Additional information
No response
Activity