reactjs 我收到此错误- FirebaseError:Firebase:名为“[DEFAULT]”的Firebase应用程序已存在,具有不同的选项或配置(应用程序/重复应用程序)

wwtsj6pe  于 2022-12-22  发布在  React
关注(0)|答案(1)|浏览(137)
import { initializeApp } from 'firebase/app'
import { getAuth } from 'firebase/auth'
import { getFirestore } from "firebase/firestore"; 

const firebaseConfig = {
  apiKey: process.env.NEXT_PUBLIC_FIREBASE_PUBLIC_API_KEY,
  authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID
}


const app = initializeApp(firebaseConfig)
export const auth = getAuth()

export const db = getFirestore(app)
console.log('db', db)

我已经尝试了长度的事情,但它似乎不工作与firebase v9。我需要导出数据库了。
没有连接到数据库,应用程序工作正常。

djmepvbi

djmepvbi1#

经过大量的试验和错误弄清楚:)

import * as firebase from "firebase/app";
import { logEvent } from "firebase/analytics";
import { getAnalytics } from "firebase/analytics";

const firebaseConfig = {
    apiKey: process.env.API_KEY,
    authDomain: process.env.AUTH_DOMAIN,
    projectId: process.env.PROJECT_ID,
    storageBucket: process.env.STORAGE_BUCKET,
    messagingSenderId: process.env.MESSAGING_SENDER_ID,
    appId: process.env.APP_ID,
    measurementId: process.env.MEASUREMENT_ID
};

let app;

if (!firebase.getApps().length) {
    app = firebase.initializeApp(firebaseConfig);
} else {
    // if already initialized, use that one
    app = firebase.getApp(); 
}

export function analyticsLogEvents(event:string, params:any) {
    let analytics;
    if (typeof window !== "undefined") {
        analytics = getAnalytics(app);
        logEvent(analytics, event, params);
    }
}

相关问题