Using the Web SDK, this would work: firebase.app().options.authDomain.split('.')[0]
which would return the app name (myapp-31h2n
). How is this behavior possible in react-native-firebase
?
3 thoughts on “Get App config”
Comments are closed.
Using the Web SDK, this would work: firebase.app().options.authDomain.split('.')[0]
which would return the app name (myapp-31h2n
). How is this behavior possible in react-native-firebase
?
Author: Fantashit
4 thoughts on “Get App config”
-
@aarongreenwald see my comments onwards from here: #130 (comment) – it’s in the works
-
Some more info of whats done:
Examples
No need to js initialize natively initialized apps (plist/json) or have a singleton exported instance, import and go.
import firebase from 'react-native-firebase'; const defaultApp = firebase.app(); defaultApp.auth().signInAnonymously().then((user) => { console.log('defaultApp user ->', user.toJSON()); }); // as you can see there's no need to call initializeApp for apps that have been // initialized natively via google-services plist/json files, all natively initialized apps // are available immediately at app run time, even if you natively initialized more apps. // for backwards compatibility you can still call `initializeApp` for the default app - it just internally ignores initialization.
App config
import firebase from 'react-native-firebase'; // get the default app name/options that were initialized natively console.log("name", firebase.app().name); console.log("apiKey", firebase.app().options.apiKey); console.log("applicationId", firebase.app().options.appId); console.log("databaseUrl", firebase.app().options.databaseURL); console.log("messagingSenderId", firebase.app().options.messagingSenderId); console.log("projectId", firebase.app().options.projectId); console.log("storageBucket", firebase.app().options.storageBucket);
Dynamically create new firebase app instances
import firebase from 'react-native-firebase'; const yourAppConfig = { clientId: 'x', appId: 'x', apiKey: 'x', databaseURL: 'x', storageBucket: 'x', messagingSenderId: 'x', projectId: 'x', }; const anotherApp = firebase.initializeApp(yourAppConfig, 'anotherApp'); // dynamically created apps aren't available immediately due to the // the way the react native environment works, therefore you must // wait for an `onReady` state before calling any modules/methods // otherwise you will most likely run into `app not initialized` exceptions anotherApp.onReady().then((app) => { // --- ready --- // use `app` or `anotherApp` to access modules and methods // or you can also do: firebase.app('anotherApp').auth().signInAnonymously().then((user) => { console.log('defaultApp user ->', user.toJSON()); }); });
Notes
- Only
auth
,database
andstorage
modules support multiple apps on the official firebase SDK, therefore when calling a rnfirebase method on a module not listed above on any app (except for the default app) will cause an exception to be thrown.
Feedback/thoughts on the above welcome
- Only
-
Support for multiple apps and support for getting app config has been added in v3. Thanks for the feature request.
Will close this now. Check out the v3 change logs and docs when it lands for usage.
-
Pingback: rolex replica
Comments are closed.
Using the Web SDK, this would work: firebase.app().options.authDomain.split('.')[0]
which would return the app name (myapp-31h2n
). How is this behavior possible in react-native-firebase
?
Author: Fantashit
1 thought on “Get App config”
-
Support for multiple apps and support for getting app config has been added in v3. Thanks for the feature request.
Will close this now. Check out the v3 change logs and docs when it lands for usage.
Comments are closed.
@aarongreenwald see my comments onwards from here: #130 (comment) – it’s in the works
Some more info of whats done:
Examples
No need to js initialize natively initialized apps (plist/json) or have a singleton exported instance, import and go.
App config
Dynamically create new firebase app instances
Notes
auth
,database
andstorage
modules support multiple apps on the official firebase SDK, therefore when calling a rnfirebase method on a module not listed above on any app (except for the default app) will cause an exception to be thrown.Feedback/thoughts on the above welcome
Support for multiple apps and support for getting app config has been added in v3. Thanks for the feature request.
Will close this now. Check out the v3 change logs and docs when it lands for usage.