reactjsfirebasereact-nativefirebase-authentication

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


I am getting this error when I was trying to connect firebase with my React Native App.

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

I have added my code here-

    import { initializeApp } from "firebase/app";
    import { getAuth } from "firebase/auth";
    import { getFirestore } from "firebase/firestore";

   // Your web app's Firebase configuration
const RNfirebaseConfig = {
  apiKey: "........",
  authDomain: "note-app-rn.firebaseapp.com",
  projectId: "note-app-rn",
  storageBucket: "note-app-rn.appspot.com",
  messagingSenderId: ".....",
  appId: "......"
};

const app = initializeApp(RNfirebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);

Solution

  • try this,

    import firebase from '@react-native-firebase/app';
    import '@react-native-firebase/auth';
    import '@react-native-firebase/firestore';
    
    const RNfirebaseConfig = {
      apiKey: "........",
      authDomain: "note-app-rn.firebaseapp.com",
      projectId: "note-app-rn",
      storageBucket: "note-app-rn.appspot.com",
      messagingSenderId: ".....",
      appId: "......"
    };
    
    let app;
    if (firebase.apps.length === 0) {
        app = firebase.initializeApp(RNfirebaseConfig )
    } else {
        app = firebase.app()
    }
    
    const db = firebase.firestore();
    const auth = firebase.auth();