Vitaly Menchikovsky
Vitaly Menchikovsky

Reputation: 8884

How to change admin.initializeApp when deploying different environments

I am using Firebase Functions. I have 2 environments: one for dev and other for staging.

My question is how can I change admin.initializeApp config when deploying to each environment because the databaseURL is changing:

admin.initializeApp({
  credential: [...],
  databaseURL: "someurl"
});

Thanks!

Upvotes: 4

Views: 14099

Answers (2)

Umair A.
Umair A.

Reputation: 6873

Doug Stevenson answer is correct but I'd add code example.

Example:

const serviceAccount = require('../project-id-firebase-adminsdk-twinc-5yf42572ea.json')
admin.initializeApp({
   credential: admin.credential.cert(serviceAccount)
});

OR

$ export GOOGLE_APPLICATION_CREDENTIALS=/Users/JohnWick/Desktop/app/project-id-firebase-adminsdk-twinc-5yf42572ea.json

And in function file.

admin.initializeApp();

Upvotes: 0

Doug Stevenson
Doug Stevenson

Reputation: 317467

You do this just like you are using the Firebase Admin SDK in a regular node.js app. The setup instructions are here. There are also instructions in the Firebase console when you go to download the project's service account credentials.

When you download the service account key file, you can put it in your functions directory so it can be loaded with require() and passed to initializeApp.

Upvotes: 2

Related Questions