Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt plugin doesn't properly initialize FirebaseApp in server-side middleware #1573

Open
aaaaahaaaaa opened this issue Sep 17, 2024 · 0 comments

Comments

@aaaaahaaaaa
Copy link

aaaaahaaaaa commented Sep 17, 2024

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

@aaaaahaaaaa aaaaahaaaaa changed the title Nuxt plugin doesn't initialize Firebase app in server-side middleware Nuxt plugin doesn't initialize FirebaseApp in server-side middleware Sep 17, 2024
@aaaaahaaaaa aaaaahaaaaa changed the title Nuxt plugin doesn't initialize FirebaseApp in server-side middleware Nuxt plugin doesn't properly initialize FirebaseApp in server-side middleware Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant