Reputation: 419
I'm trying to initialize multiple firebase projects in react but am getting a weird error saying × `Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
I` picked a completely different string , but it's still not working. Can someone pls explain what I'm doing wrong? Thanks for the help!
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;
Upvotes: 3
Views: 6064
Reputation: 666
If you are using multiple app in the same project then you have to give each app instance a unique name like this:
const app = initializeApp(firebaseConfig, 'appA');
const app = initializeApp(firebaseConfig2, 'appB');
Upvotes: 2
Reputation: 247
You can't use the same config for 2 intializeApp
just initialize it once and then export your app
You have to give your second firebase.initializeApp(firebaseConfig2)
a name after your config. So it would look something like this.
firebase.initializeApp(firebaseConfig2, 'secondary');
You can read this post to know more about it: https://firebase.google.com/docs/configure/
Upvotes: 9