The App module is available by default once you have installed the React Native Firebase library by following the Getting Started documentation. The App module currently provides the following functionality:
- Creating Secondary Firebase App Instances.
- Exposing Utilities to aid development.
| Platforms | Android, iOS (native Firebase SDK) |
| New Architecture | Required from v26. See Migrating to v26. |
Platform notes: initializeApp is async on React Native (native bridge). registerVersion is web only and throws on native platforms.
Unlike the Firebase Web SDK, there is no need to manually call the initializeApp
method with your project credentials. The native Android & iOS SDKs automatically connect to your Firebase project using
the credentials provided during the Getting Started installation steps. The app module does however provide support
for manually initializing secondary Firebase app instances.
Currently, the native Firebase SDKs only provide functionality for creating secondary apps on the following services:
- App Check.
- Authentication.
- Realtime Database.
- Cloud Firestore.
- Cloud Functions.
- Cloud Storage.
- ML.
- Installations.
- Remote Config.
The module exposes an initializeApp method which accepts arguments containing the credentials and options for your secondary
apps:
import { initializeApp } from '@react-native-firebase/app';
// Your secondary Firebase project credentials...
const credentials = {
clientId: '',
appId: '',
apiKey: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: '',
projectId: '',
};
const config = {
name: 'SECONDARY_APP',
};
await initializeApp(credentials, config);Note that if you use multiple platforms, you will need to use the credentials relevant to that platform:
import { initializeApp } from '@react-native-firebase/app';
import { Platform } from 'react-native';
// Your secondary Firebase project credentials for Android...
const androidCredentials = {
clientId: '',
appId: '',
apiKey: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: '',
projectId: '',
};
// Your secondary Firebase project credentials for iOS...
const iosCredentials = {
clientId: '',
appId: '',
apiKey: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: '',
projectId: '',
};
// Select the relevant credentials
const credentials = Platform.select({
android: androidCredentials,
ios: iosCredentials,
});
const config = {
name: 'SECONDARY_APP',
};
await initializeApp(credentials, config);Once created, you can confirm the app instance has been created by accessing the apps property on the module:
import { getApps } from '@react-native-firebase/app';
const apps = getApps();
apps.forEach(app => {
console.log('App name: ', app.name);
});You can switch app instances at any time whilst developing by calling the app method with the name of the secondary app:
import { getApp } from '@react-native-firebase/app';
import { getAuth } from '@react-native-firebase/auth';
getAuth(getApp('SECONDARY_APP')).currentUser;Or pass the secondary app instance you created above directly to the desired module, for example:
import { getApp, initializeApp } from '@react-native-firebase/app';
import { getAuth } from '@react-native-firebase/auth';
const secondaryApp = await initializeApp(credentials, config);
getAuth(secondaryApp).currentUser;You can delete any secondary instances by calling the delete method on the instance:
await getApp('SECONDARY_APP').delete();
Core / App