duronic
duronic

Reputation: 167

No Firebase App '[Default] has been created - call firebase.initializeApp()

My app is connected to firebase and auth is working fine. However, when trying to use firestore I can't figure out this problem.

Possible Unhandled Promise Rejection (id: 0): Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

I am getting the above error however, I am already calling initializeApp and not sure what else to try. I am trying to get access to a collection on firestore and print it out but it gives me the error when I try to access firestore.

I have tried doing console.log(firebase.app().name) which gives the name of the app, so not sure how it is not initialised.

var firebaseConfig = {
  apiKey: "***",
  authDomain: "***",
  databaseURL: "***",
  projectId: "***",
  storageBucket: "***",
  messagingSenderId: "***",
  appId: "***",
  measurementId: "****",
}

firebase.initializeApp(firebaseConfig)
const db = firebase.firestore()

My imports are

import "firebase/firestore"
import firebase from "firebase"
import firestore from "@react-native-firebase/firestore"

I have tried so many different questions on here and forums but nothing has helped

Upvotes: 0

Views: 11642

Answers (2)

Mohamed Reda
Mohamed Reda

Reputation: 1607

Make sure that you made all the configuration correctly by following this video

And just make sure that the first 2 lines at main function are (follow the same order):

 void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  //rest of the code
  runApp(MyApp());
}

Upvotes: 4

duronic
duronic

Reputation: 167

As per Kishan above. I added the google-services.json file into the android level folder and modified both build.gradle files.

https://firebase.google.com/docs/android/setup followed step 3 here to update the build.gradle files to use google-services.

Upvotes: 3

Related Questions