Issue
I getting following error when try to read the data from firebase using redux.
React-Native: Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app)
The connections with firebase works fine, cause I can create a new user and add new data to Firestore.
- I have added my info.plist file
- I have have config firebase in the app delegate
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
My redux Actions.js
import firebase from 'firebase/app';
import 'firebase/firestore';
import { USER_STATE_CHANGE, CLEAR_DATA, } from '../constans/index'
//fetch UserInfo from firebase
export function fetchUser() {
return (dispatch) => {
firebase
.firestore()
.collection("users")
.doc(firebase.auth().currentUser.uid)
.get()
.then((snapshot) => {
if (snapshot.exists) {
dispatch({ type: USER_STATE_CHANGE, currentUser: snapshot.data() });
} else {
console.log('does not exist');
}
});
};
}
So do anyone have a clue of what I should do. If I have added the "config" in Xcode, should I also do in App.js?
Solution
You need to initialize the firebase config file in your application like this:
const reactNativeFirebaseConfig = {
apiKey: ...,
authDomain: '...',
databaseURL: ...,
projectId: ...,
storageBucket: ...,
messagingSenderId: ...,
appId: ...,
};
if (firebase.apps.length === 0) {
firebase.initializeApp(reactNativeFirebaseConfig);
}
firebase.firestore();
Answered By - Dániel Boros
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.