React-Native: Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app) site:stackoverflow.com

Viewed 6747

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.

  1. I have added my info.plist file
  2. 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?

1 Answers

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();
Related