Core React Native Firebase implementation providing foundation for all Firebase services across iOS and Android platforms
npx @tessl/cli install tessl/npm-react-native-firebase--app@23.3.00
# React Native Firebase App
1
2
React Native Firebase App is the core foundation package that provides Firebase integration for React Native applications. It serves as the main entry point and manager for all Firebase services, offering both traditional Firebase v8 API compatibility and modern v9+ modular functions. The package handles app initialization, configuration management, cross-platform native bridge functionality, and provides essential utilities for file operations and Google Play Services integration.
3
4
## Package Information
5
6
- **Package Name**: @react-native-firebase/app
7
- **Package Type**: npm
8
- **Language**: JavaScript/TypeScript
9
- **Installation**: `npm install @react-native-firebase/app` or `yarn add @react-native-firebase/app`
10
11
## Core Imports
12
13
ES Modules/TypeScript:
14
15
```typescript
16
import firebase from '@react-native-firebase/app';
17
import { initializeApp, getApp, getApps, SDK_VERSION } from '@react-native-firebase/app';
18
```
19
20
CommonJS:
21
22
```javascript
23
const firebase = require('@react-native-firebase/app').default;
24
const { initializeApp, getApp, getApps, SDK_VERSION } = require('@react-native-firebase/app');
25
```
26
27
## Basic Usage
28
29
```typescript
30
import firebase, { initializeApp, getApp } from '@react-native-firebase/app';
31
32
// Access the default app (automatically initialized)
33
const defaultApp = firebase.app();
34
console.log(defaultApp.name); // '[DEFAULT]'
35
36
// Initialize a secondary app with custom config
37
const secondaryApp = await initializeApp({
38
apiKey: 'your-api-key',
39
authDomain: 'your-project.firebaseapp.com',
40
projectId: 'your-project-id',
41
appId: 'your-app-id'
42
}, 'secondary');
43
44
// Get an app instance
45
const myApp = getApp('secondary');
46
47
// Use utils for file operations
48
const utils = firebase.utils();
49
console.log(utils.FilePath.DOCUMENT_DIRECTORY);
50
```
51
52
## Architecture
53
54
React Native Firebase App is structured around several key components:
55
56
- **Firebase Root Object**: Traditional v8-style API providing `firebase.app()`, `firebase.utils()` access patterns
57
- **Modular Functions**: Modern v9+ style functions (`initializeApp`, `getApp`, etc.) for tree-shaking and improved bundling
58
- **Native Bridge**: Cross-platform bridge connecting JavaScript to native iOS/Android Firebase SDKs
59
- **App Registry**: Internal registry managing multiple Firebase app instances and their lifecycle
60
- **Utils Module**: Platform-specific utilities for file paths, Google Play Services, and Test Lab detection
61
- **Type System**: Comprehensive TypeScript definitions for all Firebase app functionality
62
63
## Capabilities
64
65
### App Management
66
67
Core Firebase app initialization, configuration, and lifecycle management. Essential for setting up Firebase in React Native applications.
68
69
```typescript { .api }
70
function initializeApp(options: FirebaseAppOptions, name?: string): Promise<FirebaseApp>;
71
function initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): Promise<FirebaseApp>;
72
function getApp(name?: string): FirebaseApp;
73
function getApps(): FirebaseApp[];
74
function deleteApp(app: FirebaseApp): Promise<void>;
75
function registerVersion(libraryKeyOrName: string, version: string, variant?: string): Promise<void>;
76
77
const SDK_VERSION: string;
78
```
79
80
[App Management](./app-management.md)
81
82
### Configuration and Logging
83
84
Firebase SDK configuration, logging control, and platform-specific settings management.
85
86
```typescript { .api }
87
function setLogLevel(logLevel: LogLevelString): void;
88
function setReactNativeAsyncStorage(asyncStorage: ReactNativeAsyncStorage): void;
89
function onLog(logCallback: (params: LogCallbackParams) => void, options?: any): void;
90
```
91
92
[Configuration](./configuration.md)
93
94
### Native Platform Integration
95
96
Access to native platform data, preferences, and Firebase configuration from React Native.
97
98
```typescript { .api }
99
function metaGetAll(): Promise<{[key: string]: string | boolean}>;
100
function jsonGetAll(): Promise<{[key: string]: string | boolean}>;
101
function preferencesGetAll(): Promise<{[key: string]: string | boolean}>;
102
function preferencesClearAll(): Promise<void>;
103
function preferencesSetBool(key: string, value: boolean): Promise<void>;
104
function preferencesSetString(key: string, value: string): Promise<void>;
105
```
106
107
[Native Integration](./native-integration.md)
108
109
### Utils and File Operations
110
111
Platform utilities including file path constants, Google Play Services helpers, and Test Lab detection.
112
113
```typescript { .api }
114
interface Utils.Module {
115
isRunningInTestLab: boolean;
116
playServicesAvailability: PlayServicesAvailability;
117
getPlayServicesStatus(): Promise<PlayServicesAvailability>;
118
promptForPlayServices(): Promise<void>;
119
makePlayServicesAvailable(): Promise<void>;
120
resolutionForPlayServices(): Promise<void>;
121
}
122
123
interface Utils.FilePath {
124
MAIN_BUNDLE: string;
125
CACHES_DIRECTORY: string;
126
DOCUMENT_DIRECTORY: string;
127
EXTERNAL_DIRECTORY: string | null;
128
EXTERNAL_STORAGE_DIRECTORY: string | null;
129
TEMP_DIRECTORY: string;
130
LIBRARY_DIRECTORY: string;
131
PICTURES_DIRECTORY: string;
132
MOVIES_DIRECTORY: string;
133
}
134
```
135
136
[Utils](./utils.md)
137
138
## Types
139
140
```typescript { .api }
141
interface FirebaseApp {
142
readonly name: string;
143
readonly options: FirebaseAppOptions;
144
automaticDataCollectionEnabled: boolean;
145
delete(): Promise<void>;
146
utils(): Utils.Module;
147
}
148
149
interface FirebaseAppOptions {
150
appId: string;
151
apiKey?: string;
152
databaseURL?: string;
153
projectId: string;
154
measurementId?: string;
155
storageBucket?: string;
156
messagingSenderId?: string;
157
clientId?: string;
158
androidClientId?: string;
159
deepLinkURLScheme?: string;
160
[name: string]: any;
161
}
162
163
interface FirebaseAppConfig {
164
name?: string;
165
automaticDataCollectionEnabled?: boolean;
166
automaticResourceManagement?: boolean;
167
}
168
169
interface NativeFirebaseError extends Error {
170
readonly code: string;
171
readonly message: string;
172
readonly namespace: string;
173
readonly nativeErrorCode: string | number;
174
readonly nativeErrorMessage: string;
175
}
176
177
interface ReactNativeAsyncStorage {
178
setItem: Function;
179
getItem: Function;
180
removeItem: Function;
181
[key: string]: any;
182
}
183
184
type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
185
186
interface LogCallbackParams {
187
level: LogLevelString;
188
message: string;
189
args: unknown[];
190
type: string;
191
}
192
193
interface PlayServicesAvailability {
194
status: PlayServicesAvailabilityStatusCodes;
195
isAvailable: boolean;
196
hasResolution: boolean | undefined;
197
isUserResolvableError: boolean | undefined;
198
error: string | undefined;
199
}
200
201
enum PlayServicesAvailabilityStatusCodes {
202
API_UNAVAILABLE = 16,
203
CANCELED = 13,
204
DEVELOPER_ERROR = 10,
205
DRIVE_EXTERNAL_STORAGE_REQUIRED = 1500,
206
INTERNAL_ERROR = 8,
207
INTERRUPTED = 15,
208
INVALID_ACCOUNT = 5,
209
LICENSE_CHECK_FAILED = 11,
210
NETWORK_ERROR = 7,
211
RESOLUTION_REQUIRED = 6,
212
RESTRICTED_PROFILE = 20,
213
SERVICE_DISABLED = 3,
214
SERVICE_INVALID = 9,
215
SERVICE_MISSING = 1,
216
SERVICE_MISSING_PERMISSION = 19,
217
SERVICE_UPDATING = 18,
218
SERVICE_VERSION_UPDATE_REQUIRED = 2,
219
SIGN_IN_FAILED = 17,
220
SIGN_IN_REQUIRED = 4,
221
SUCCESS = 0,
222
TIMEOUT = 14,
223
}
224
```