0

I am having quite an issue, browse the entire stack overflow to find answer but unfortunately no luck yet.

My issue is the following:

I have a Next JS app, deployed to vercel; I am using their serverless API. So I am using firebase-admin library in the /api folders, to handle my backend stuff. (including database()) But then I must also use firebase.database() from the frontend, in order to use listeners / websocket (unavailable through serverless function of course)

But then I cannot initialize both admin database() AND basic firebase.database(), the error I get being:

Error: FIREBASE FATAL ERROR: Database initialized multiple times. Please make sure the format of the database URL matches with each database() call.

And now I am stuck, I feel like I will have to migrate my API entirely to something else so I can separate the firebase admin and use my firebase.database() from the front as expected... that's quite sad.

Any help is very much welcome!

Gigalink
  • 170
  • 8
  • 1
    Have you had a look at Next.js [`with-firebase`](https://github.com/vercel/next.js/tree/canary/examples/with-firebase) official example? – juliomalves Sep 04 '21 at 17:19
  • 1
    Actually yes, countless time. However I checked it once more following your advice, and realized that although they import all necessary dependencies they don't actually export anything else but firebase from their clientApp.js. I was actually trying to export db=firebase.database() from my clientApp.js and that is what broke it. Now, from my component if I import firebase and use firebase.database() it actually does work! I would still love to have an explaination as to why I couldn't export firebase.database(), but thank you so much nonetheless for bringing me back to the right place! :) – Gigalink Sep 04 '21 at 17:32

0 Answers0