1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

複数のFirebase Realtime Databaseに接続したい

1
Posted at

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"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?