diff --git a/frontend-web/src/firebase.js b/frontend-web/src/firebase.js index 9f5e6fb4..26d64d59 100644 --- a/frontend-web/src/firebase.js +++ b/frontend-web/src/firebase.js @@ -1,5 +1,5 @@ // Import the functions you need from the SDKs you need -import { initializeApp } from "firebase/app"; +import { initializeApp, getApps, getApp } from "firebase/app"; import { getAuth } from "firebase/auth"; import { getDataConnect } from 'firebase/data-connect'; import { connectorConfig } from '@dataconnect/generated'; @@ -14,7 +14,16 @@ const firebaseConfig = { appId: import.meta.env.VITE_FIREBASE_APP_ID }; -// Initialize Firebase -const app = initializeApp(firebaseConfig); +// Initialize Firebase app only once +let app; +if (getApps().length === 0) { // Check if no app is already initialized + app = initializeApp(firebaseConfig); +} else { + app = getApp(); // If already initialized, use the existing app +} + export const dataConnect = getDataConnect(app, connectorConfig); -export const auth = getAuth(app); \ No newline at end of file +export const auth = getAuth(app); + +// For debugging purposes, if you previously added this, it can stay or be removed +// window.firebaseAuth = auth; \ No newline at end of file