fix : local dev without env variables
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { FirebaseOptions, initializeApp } from "firebase/app";
|
||||
import { getAnalytics, isSupported, logEvent } from "firebase/analytics";
|
||||
|
||||
const firebaseConfig: FirebaseOptions = {
|
||||
const firebaseConfig: FirebaseOptions | undefined = process.env
|
||||
.NEXT_PUBLIC_FIREBASE_PROJECT_ID
|
||||
? {
|
||||
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
|
||||
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
|
||||
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
||||
@@ -9,12 +11,13 @@ const firebaseConfig: FirebaseOptions = {
|
||||
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
||||
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
||||
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
||||
};
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const app = initializeApp(firebaseConfig);
|
||||
const app = firebaseConfig ? initializeApp(firebaseConfig) : undefined;
|
||||
|
||||
isSupported().then((supported) => {
|
||||
if (supported) {
|
||||
if (supported && app) {
|
||||
getAnalytics(app);
|
||||
}
|
||||
});
|
||||
@@ -26,7 +29,7 @@ export const logAnalyticsEvent = async (
|
||||
if (window.location.hostname === "localhost") return;
|
||||
|
||||
const supported = await isSupported();
|
||||
if (!supported) return;
|
||||
if (!supported || !app) return;
|
||||
|
||||
const analytics = getAnalytics(app);
|
||||
logEvent(analytics, eventName, eventParams);
|
||||
|
||||
Reference in New Issue
Block a user