0
# App Management
1
2
Firebase app initialization, configuration, and lifecycle management functionality. These functions provide control over Firebase app instances in React Native applications.
3
4
## Capabilities
5
6
### Initialize App
7
8
Creates and initializes a new Firebase app instance with the provided configuration options.
9
10
```typescript { .api }
11
/**
12
* Initializes a Firebase app with the provided options and name
13
* @param options - Options to configure the services used in the app
14
* @param name - The optional name of the app to initialize ('[DEFAULT]' if omitted)
15
* @returns Promise resolving to the initialized Firebase app
16
*/
17
function initializeApp(options: FirebaseAppOptions, name?: string): Promise<FirebaseApp>;
18
19
/**
20
* Initializes a Firebase app with the provided options and config
21
* @param options - Options to configure the services used in the app
22
* @param config - The optional config for your firebase app
23
* @returns Promise resolving to the initialized Firebase app
24
*/
25
function initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): Promise<FirebaseApp>;
26
```
27
28
**Usage Examples:**
29
30
```typescript
31
import { initializeApp } from '@react-native-firebase/app';
32
33
// Initialize default app
34
const defaultApp = await initializeApp({
35
apiKey: 'AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk',
36
authDomain: 'my-project.firebaseapp.com',
37
projectId: 'my-project',
38
appId: '1:12345678901:android:abc123def456'
39
});
40
41
// Initialize named app
42
const secondaryApp = await initializeApp({
43
apiKey: 'different-api-key',
44
projectId: 'secondary-project',
45
appId: 'secondary-app-id'
46
}, 'secondary');
47
48
// Initialize with config
49
const configuredApp = await initializeApp({
50
apiKey: 'api-key',
51
projectId: 'project-id',
52
appId: 'app-id'
53
}, {
54
name: 'configured',
55
automaticDataCollectionEnabled: false,
56
automaticResourceManagement: true
57
});
58
```
59
60
### Get App
61
62
Retrieves an existing Firebase app instance by name.
63
64
```typescript { .api }
65
/**
66
* Retrieves an instance of a Firebase app
67
* @param name - The optional name of the app to return ('[DEFAULT]' if omitted)
68
* @returns The requested Firebase app instance
69
*/
70
function getApp(name?: string): FirebaseApp;
71
```
72
73
**Usage Examples:**
74
75
```typescript
76
import { getApp } from '@react-native-firebase/app';
77
78
// Get default app
79
const defaultApp = getApp();
80
console.log(defaultApp.name); // '[DEFAULT]'
81
82
// Get named app
83
const secondaryApp = getApp('secondary');
84
console.log(secondaryApp.name); // 'secondary'
85
```
86
87
### Get Apps
88
89
Returns an array of all currently initialized Firebase app instances.
90
91
```typescript { .api }
92
/**
93
* Gets the list of all initialized apps
94
* @returns An array of all initialized Firebase apps
95
*/
96
function getApps(): FirebaseApp[];
97
```
98
99
**Usage Examples:**
100
101
```typescript
102
import { getApps } from '@react-native-firebase/app';
103
104
// Get all initialized apps
105
const allApps = getApps();
106
console.log(`Total apps: ${allApps.length}`);
107
108
allApps.forEach(app => {
109
console.log(`App: ${app.name}, Project: ${app.options.projectId}`);
110
});
111
```
112
113
### Delete App
114
115
Renders a Firebase app unusable and frees up all associated resources.
116
117
```typescript { .api }
118
/**
119
* Renders this app unusable and frees the resources of all associated services
120
* @param app - The app to delete
121
* @returns Promise that resolves when the app is deleted
122
*/
123
function deleteApp(app: FirebaseApp): Promise<void>;
124
```
125
126
**Usage Examples:**
127
128
```typescript
129
import { deleteApp, getApp, SDK_VERSION } from '@react-native-firebase/app';
130
131
// Delete a specific app
132
const myApp = getApp('secondary');
133
await deleteApp(myApp);
134
135
console.log('App deleted successfully');
136
137
// Get SDK version
138
console.log('Firebase SDK Version:', SDK_VERSION);
139
```
140
141
### Register Version
142
143
Registers a library's name and version for platform logging purposes. Note: This function is only supported on Web and will throw an error on React Native.
144
145
```typescript { .api }
146
/**
147
* Registers a library's name and version for platform logging purposes
148
* @param libraryKeyOrName - Library name or key
149
* @param version - Library version
150
* @param variant - Library variant (optional)
151
* @returns Promise that resolves when registration is complete
152
* @throws Error on React Native platforms (only supported on Web)
153
*/
154
function registerVersion(libraryKeyOrName: string, version: string, variant?: string): Promise<void>;
155
```
156
157
**Usage Examples:**
158
159
```typescript
160
import { registerVersion } from '@react-native-firebase/app';
161
162
try {
163
// This will throw an error on React Native
164
await registerVersion('my-library', '1.0.0', 'react-native');
165
} catch (error) {
166
console.log('registerVersion is only supported on Web');
167
}
168
```
169
170
### SDK Version
171
172
The current version of the React Native Firebase SDK.
173
174
```typescript { .api }
175
/**
176
* The current SDK version string
177
*/
178
const SDK_VERSION: string;
179
```
180
181
**Usage Examples:**
182
183
```typescript
184
import { SDK_VERSION } from '@react-native-firebase/app';
185
186
console.log('React Native Firebase version:', SDK_VERSION);
187
188
// Useful for debugging or logging
189
console.log(`App initialized with RNFirebase ${SDK_VERSION}`);
190
```
191
192
## Traditional Firebase API
193
194
The traditional Firebase v8-style API is also available through the default export:
195
196
```typescript
197
import firebase from '@react-native-firebase/app';
198
199
// Access default app
200
const app = firebase.app();
201
202
// Initialize new app (traditional style)
203
const newApp = await firebase.initializeApp(options, name);
204
205
// Get app (traditional style)
206
const myApp = firebase.app('myAppName');
207
208
// Get all apps
209
const apps = firebase.apps;
210
```
211
212
## Error Handling
213
214
App management functions may throw Firebase-specific errors:
215
216
```typescript
217
import { getApp } from '@react-native-firebase/app';
218
219
try {
220
const app = getApp('nonexistent');
221
} catch (error) {
222
console.log(error.code); // Firebase error code
223
console.log(error.message); // Error message
224
}
225
```
226
227
## App Instance Properties
228
229
Once you have a Firebase app instance, you can access its properties and methods:
230
231
```typescript
232
import { getApp } from '@react-native-firebase/app';
233
234
const app = getApp();
235
236
// Read-only properties
237
console.log(app.name); // App name
238
console.log(app.options); // App configuration options
239
240
// Settable properties
241
app.automaticDataCollectionEnabled = false;
242
243
// Methods
244
await app.delete(); // Delete the app
245
const utils = app.utils(); // Get utils module
246
```