Vue.jsで複数Firebaseに接続したい
簡単なメモ
firebaseモジュールと、それぞれのconfig情報をimportする。
main.js
import * as firebase from 'firebase'
import {FirebaseConfig} from './firebase-config'
import {secondaryFirebaseConfig} from './firebase-config-second'
あ、ちなみにconfig.jsはこんな感じ
firebase-config.js
export const firebaseConfig = {
apiKey: 'your_apiKey',
authDomain: 'your_authDomain',
databaseURL: 'your_databaseURL',
projectId: 'your_projectId',
storageBucket: 'your_storageBucket',
messagingSenderId: 'your_messagingSenderId',
}
そして、それぞれをinitializeする
main.js
var first = firebase.initializeApp(firebaseConfig)
var secondary = firebase.initializeApp(secondaryFirebaseConfig, 'secondary')
ドキュメントによると、ここでの 'secondary' はapp.nameを設定しているみたい
hoge.js
// Initialize the default app
firebase.initializeApp(defaultAppConfig);
// Initialize another app with a different config
var otherApp = firebase.initializeApp(otherAppConfig, "other");
console.log(firebase.app().name); // "[DEFAULT]"
console.log(otherApp.name); // "other"