I am using Firebase for Next.js project but the default code provided by firebase is not working, its’s showing "Failed to fetch inventory. Please try again."
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: " ",
authDomain: " ",
projectId: " ",
storageBucket: " ",
messagingSenderId: " ",
appId: " ",
measurementId: " "
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
>Solution :
you initialized firebase but did not export it
- import getFirestore
- // Initialize Firestore and export it
const firestore = getFirestore(app);
export { firestore, analytics };
code:
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAnalytics } from "firebase/analytics";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBqonQ-u5_uwt3fwhtZxZH1NDvXZJfX23Q",
authDomain: "pantry-app-969e3.firebaseapp.com",
projectId: "pantry-app-969e3",
storageBucket: "pantry-app-969e3.appspot.com",
messagingSenderId: "282738394306",
appId: "1:282738394306:web:6d35c41d9e0ef73e8ae75b",
measurementId: "G-XN12QJ3SMH"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
// Initialize Firestore and export it
const firestore = getFirestore(app);
export { firestore, analytics };