I'm trying to implement and export the firebase analytics module in Next.js (firebase v9)
I get the error "ReferenceError: window is not defined" for the following code snippet. All previous functions working great.
Any ideas how to fix this?
import { initializeApp, getApps, getApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getAuth } from 'firebase/auth'
import { getFirestore } from '@firebase/firestore'
const firebaseConfig = {
//...
};
// Initialize Firebase
const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();
const auth = getAuth();
const db = getFirestore(app)
// try to add analytics
const analytics = getAnalytics(app)
export {auth, db, analytics}