我正在尝试在react中初始化多个firebase项目,但出现一个奇怪的错误,提示× `Firebase:名为'[DEFAULT]'的Firebase应用已存在(app / duplicate-app)。
我`选择了一个完全不同的字符串,但是仍然无法正常工作。有人可以解释我在做什么错吗?谢谢您的帮助!
reference.js
import * as firebase from "firebase";
var config = {
apiKey: "AIzaSyDsTsClk8l2l5yLNu_eG-R06Usv4Oi_NvQ",
authDomain: "d-ucukgx.firebaseapp.com",
databaseURL: "https://d-ucukgx.firebaseio.com",
projectId: "d-ucukgx",
storageBucket: "d-ucukgx.appspot.com",
messagingSenderId: "1031835936266"
};
firebase.initializeApp(config);
const databaseRef = firebase.database().ref();
export const ChampsRef = databaseRef.child("Champs");
export const authRef = firebase.auth();
export const timeRef = firebase.database.ServerValue.TIMESTAMP;
export default databaseRef;
config / dev.js
import * as firebase from "firebase";
var firebaseConfig2 = {
apiKey: "AIzaSyDsTsClk8l2l5yLNu_eG-R06Usv4Oi_NvQ",
authDomain: "d-ucukgx.firebaseapp.com",
databaseURL: "https://d-ucukgx.firebaseio.com",
projectId: "d-ucukgx",
storageBucket: "d-ucukgx.appspot.com",
messagingSenderId: "1031835936266"
};
firebase.initializeApp(firebaseConfig2);
var app = firebase.initializeApp(firebaseConfig2, "auth");
export default app;
答案 0 :(得分:0)
您不能将相同的配置用于2 intializeApp
,只需对其初始化一次,然后导出您的app
您必须在配置后给第二个firebase.initializeApp(firebaseConfig2)
命名。所以看起来像这样。
firebase.initializeApp(firebaseConfig2, 'secondary');
您可以阅读这篇文章以了解更多信息:https://firebase.google.com/docs/configure/