This is a snippet that uses firebase's firebase-admin
to initialize multiple firebase projects in one admin application.
import 'firebase';
import * as admin from 'firebase-admin';
import firstServiceAccount from 'path/to/service-account-1';
import secondServiceAccount from 'path/to/service-account-2';
var _first = admin.initializeApp(
{
credential: admin.credential.cert(firstServiceAccount),
databaseURL: 'https://<1st-db-name>.firebaseio.com'
},
'first' // this name will be used to retrieve firebase instance. E.g. first.database();
);
var _second = admin.initializeApp(
{
credential: admin.credential.cert(secondServiceAccount),
databaseURL: 'https://<2nd-db-name>.firebaseio.com'
},
'second' // this name will be used to retrieve firebase instance. E.g. second.database();
);
export const first = _first;
export const second = _second;
import { first, second } from '../path/to/the/file/above'
first.database();
second.database();
If I have more than two Firebase applications and I want to initialize only one at a time based on the variable I pass, is it possible to do that? is there any other way to initialize only one project without initializing both at same time?