I'm using firebase for auth and db, and AWS lambda for cloud functions.
To add firebase to my JS project, I initializeApp
with the firebase config as parameter, as documented here : https://firebase.google.com/docs/web/setup.
As documented here : https://firebase.google.com/docs/admin/setup, I also need to initializeApp
in my lambda function.
Something as follows here :
const admin = require('firebase-admin');
const serviceAccount = require('../path/to/service-account.json');
const firebaseAdmin = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "dB_URL"
});
The credentials come from the firebase-admin library, so I cannot add this to my web firebase config. So, I need to initialize twice.
However, if I proceed like this, the server will throw an error :
The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once.But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.
Am I missing something here ? What's the best practice ? I'm confused.
Someone faced the same issue before it seems : Use Firebase SDK with Netlify Lambda Functions
What worked for this user was to use the REST API as documented here : https://firebase.google.com/docs/projects/api/workflow_set-up-and-manage-project
The documentation says it's in beta though.
Thanks for your kind help