Newbie question - Initialize firebase in two separate files using new api

1,914 views
Skip to first unread message

cha...@connect.hku.hk

unread,
May 19, 2016, 11:02:48 PM5/19/16
to Firebase Google Group
Hi guys,

I have upgraded to the new api and don't know how to initialize firebase refs in two seprate files:

/* CASE 1 */
// 1st file
var config = {/* ...  */};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();

// 2nd file - initialize again
var config = {/* ...  */};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();

RESULT: bundle.js:535 Uncaught Error: Firebase App named '[DEFAULT]' already exists.

/* CASE 2 */
// 1st file
var config = {/* ...  */};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();

// 2nd file - don't initialize
var rootRef = firebase.database().ref();

RESULT: bundle.js:529 Uncaught Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp().

Before the new api I just call 
  1. var myFirebaseRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/");
 in each file and it works okay. What should I do? Thanks!

Kato Richardson

unread,
May 20, 2016, 11:48:48 PM5/20/16
to Firebase Google Group
Hi, please introduce yourself by name in the future.

It's hard to tell what you're doing here, since you used ... in place of some of the key insights.

When you call initializeApp() more than once, you need to specify a name for the config. See Advanced Usage here.

Note that you also need to pass a ref into the alternate app config to your second reference, assuming those configs are any different.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/d2bb699b-b358-4560-8d1f-ed02fa22b32a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

chelsea...@girlswhocode.com

unread,
Aug 14, 2016, 10:56:18 PM8/14/16
to Firebase Google Group
Hi Kato,

I'm not sure you understood the initial question. I don't think they were trying to initialize two apps, I think they were trying to reference a single app from two different HTML pages (on the same website of course). I also have the same question, and would appreciate some guidance. 

Best,
Chelsea
Reply all
Reply to author
Forward
0 new messages