Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase default code is not working for next.js

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you initialized firebase but did not export it

  1. import getFirestore
  2. // 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 };
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading