-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathfirebaseapp.js
74 lines (60 loc) · 2.32 KB
/
firebaseapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import firebase from 'firebase/app';
function multpleFirebaseApps() {
// [START firebase_options]
// The following fields are REQUIRED:
// - Project ID
// - App ID
// - API Key
const secondaryAppConfig = {
projectId: "<PROJECT_ID>",
appId: "<APP_ID>",
apiKey: "<API_KEY>",
// databaseURL: "...",
// storageBucket: "...",
};
// [END firebase_options]
// [START firebase_secondary]
// Initialize another app with a different config
const secondaryApp = firebase.initializeApp(secondaryAppConfig, "secondary");
// Access services, such as the Realtime Database
// secondaryApp.database();
// [END firebase_secondary]
}
function defaultInitOptions() {
const firebaseConfig = {
// ...
};
// [START app_default_init_options]
// Initialize Firebase with a "default" Firebase project
const defaultProject = firebase.initializeApp(firebaseConfig);
console.log(defaultProject.name); // "[DEFAULT]"
// Option 1: Access Firebase services via the defaultProject variable
let defaultStorage = defaultProject.storage();
let defaultFirestore = defaultProject.firestore();
// Option 2: Access Firebase services using shorthand notation
defaultStorage = firebase.storage();
defaultFirestore = firebase.firestore();
// [END app_default_init_options]
}
function multiProjectInitOptions() {
const firebaseConfig = {
// ...
};
const otherProjectFirebaseConfig = {
// ...
};
// [START app_multi_project_init_options]
// Initialize Firebase with a default Firebase project
firebase.initializeApp(firebaseConfig);
// Initialize Firebase with a second Firebase project
const otherProject = firebase.initializeApp(otherProjectFirebaseConfig, "other");
console.log(firebase.app().name); // "[DEFAULT]"
console.log(otherProject.name); // "otherProject"
// Use the shorthand notation to access the default project's Firebase services
const defaultStorage = firebase.storage();
const defaultFirestore = firebase.firestore();
// Use the otherProject variable to access the second project's Firebase services
const otherStorage = otherProject.storage();
const otherFirestore = otherProject.firestore();
// [END app_multi_project_init_options]
}