HRK44
HRK44

Reputation: 2762

Firebase-admin deal with multiple environments

I'm pretty new to firebase-admin (and firebase in general).

I have a project on Firebase called X and I created 2 android apps inside prod and dev.

To initialize my nodejs firebase-admin, I'm passing the service-account.json downloaded from the firebase console. At first I thought I would have one per each app, but it seems that it is a the project level.

I want to send push notifications using the messaging feature, it works fine but I'm not sure to what environment I'm sending it (I'm not the android dev, just nodejs).

My question is, how do I initialize the firebase-admin so that it points to prod or dev ? I usually use env variables for this kind of stuff, but I don't know what to pass to the initializeApp() function.

I've tried https://firebase.google.com/docs/admin/setup#initialize_multiple_apps but I don't see where I can specify dev or prod apps ?

That's how I initialize it so far :

const app = firebaseAdmin.initializeApp({
    credential: firebaseAdmin.credential.applicationDefault()
});

...

app.messaging().send(message)
 .then((response) => {
     // Response is a message ID string.
     console.log('Successfully sent message:', response);
 })
 .catch((error) => {
     console.log('Error sending message:', error);
 });

Thanks

Upvotes: 2

Views: 1409

Answers (1)

andresmijares
andresmijares

Reputation: 3744

You will need to create a project per each environment you use, this is common practice.

Depends on your use case for each you might select different pricing plans.

Export the sdk key for each one, you can instantiate based on environment variables or any other technique that might be useful for you.

Upvotes: 1

Related Questions