Skip to content

Commit

Permalink
feat: added checks for the firebase installizations (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
biratdatta authored Oct 14, 2024
1 parent 9394200 commit c00e1d8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/config/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ let messaging: any;

export const initializeFirebase = () => {
if (typeof window !== 'undefined' && !getApps().length) {
app = initializeApp(firebaseConfig);
messaging = typeof window !== 'undefined' ? getMessaging(app) : null;
if (process.env.NEXT_PUBLIC_FIREBASE_APP_ID) {
app = initializeApp(firebaseConfig);
messaging = typeof window !== 'undefined' ? getMessaging(app) : null;
} else {
console.log('Firebase configuration not found. Skipping Firebase initialization.');
}
}
};

export const requestForToken = async () => {
if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
if (typeof window !== 'undefined' && 'serviceWorker' in navigator && process.env.NEXT_PUBLIC_FIREBASE_APP_ID) {
try {
const currentToken = await getToken(messaging, {
vapidKey: process.env.NEXT_PUBLIC_FIREBASE_FCM_VAPID_KEY,
Expand All @@ -39,7 +43,7 @@ export const requestForToken = async () => {
};

export const onMessageListener = () => {
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_FIREBASE_APP_ID) {
return new Promise((resolve) => {});
}
return Promise.resolve(null);
Expand Down

0 comments on commit c00e1d8

Please sign in to comment.