使用Firebase-Ionic 2的多个项目

时间:2017-08-18 18:49:17

标签: firebase-realtime-database ionic2 firebase-authentication

我想用firebase创建一个多成语应用程序,每个应用程序都有自己的firebase项目,但我想在所有这些应用程序中共享一个firebase项目,因为每个应用程序都需要需要comun信息,例如我想用中央firebase登录。 因此,如果我可以在一个应用程序中包含两个项目的信息,那将是解决方案,但我不知道是否可能。

非常感谢

1 个答案:

答案 0 :(得分:0)

要从单个网络应用访问两个Firebase项目,您需要在代码中包含两者的配置:

var secondaryAppConfig = {
    apiKey: "<API_KEY>",
    authDomain: "<PROJECT_ID>.firebaseapp.com",
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
    storageBucket: "<BUCKET>.appspot.com",
};

然后初始化辅助应用实例并检索数据库(或您要使用的其他Firebase服务):

// Initialize another app with a different config
var secondary = firebase.initializeApp(secondaryAppConfig, "secondary");

// Retrieve the database.
var secondaryDatabase = secondary.database();

请参阅Firebase documentation for using multiple projects