vuejs / vuefire

🔥 Firebase bindings for Vue.js
https://vuefire.vuejs.org
MIT License
3.82k stars 323 forks source link

The default Firebase app does not exist. Make sure you call initializeApp() #1403

Closed crunchwrap89 closed 10 months ago

crunchwrap89 commented 11 months ago

Reproduction

*

Steps to reproduce the bug

  1. Update to latest version of firebase firebase-admin vuefire & nuxt-vuefire.
  2. Enable auth
  3. Run app with SSR enabled

Expected behavior

Application starts, initializeApp from firebase-admin should not be needed (?)

Actual behavior

Application cannot start:

✔ Vite server hmr 12 files in 135.548ms                                                                                                                                                                                                 6:57:36 PM
[nuxt] [request error] [unhandled] [500] The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.                                                                          6:57:36 PM
  at AppStore.getApp (./node_modules/firebase-admin/lib/app/lifecycle.js:65:19)  
  at getApp (./node_modules/firebase-admin/lib/app/lifecycle.js:106:36)  
  at Module.getAuth (./node_modules/firebase-admin/lib/auth/index.js:50:34)  
  at ./node_modules/nuxt-vuefire/dist/runtime/auth/plugin.server.mjs:19:43  
  at ./node_modules/nuxt/dist/app/nuxt.js:112:60  
  at fn (./node_modules/nuxt/dist/app/nuxt.js:156:44)  
  at Object.callAsync (./node_modules/unctx/dist/index.mjs:68:55)  
  at ./node_modules/nuxt/dist/app/nuxt.js:158:56  
  at Object.runWithContext (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3855:18)  
  at callWithNuxt (./node_modules/nuxt/dist/app/nuxt.js:158:24)

Additional information

Tried manually adding "initializeApp()" from firebase-admin and initialized in App.vue, also tried adding it to my auth middleware:

import { initializeApp } from "firebase-admin";
import { getApps } from "firebase-admin/app";

export default defineNuxtRouteMiddleware(async (to) => {
  if (getApps().length === 0) {
    console.log("initialize app");
    initializeApp();
  }
 ...
posva commented 11 months ago

I cannot check without a repro.

And yes, the admin sdk is needed with ssr an auth. You need to add an env variable as shown in documentation. The admin app should be initialized automatically

posva commented 11 months ago

I added a template to create the bug report: https://github.com/posva/nuxt--vuefire-repro-template

But I think you are just missing the credentials: https://vuefire.vuejs.org/nuxt/getting-started.html#Configuring-the-Admin-SDK

mitkodkn commented 11 months ago

I'm also experiencing this. Credentials are fine.

anthony32773 commented 10 months ago

I am also experiencing this as well.

posva commented 10 months ago

Closing due to inactivity. Please open a new issue with a reference to this one if you can follow up with a reproduction so I can check.

I'm adding some templates with long instructions on how to provision firebase, in case anybody found them useful.

I'm still waiting for upstream changes for the blaze plan onee


Please, don't comment to just say +1, it doesn't help in finding the problem...