Skip to content

Commit 01fb75f

Browse files
committed
feat: Add condition for checking firebase config
1 parent bd149f9 commit 01fb75f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/shared/libs/firebase.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { initializeApp } from 'firebase/app';
88
import { APP_DATA, FIREBASE_CONFIGS } from '@/shared/constants';
99
import { isLocal } from '@/shared/helpers';
1010

11-
const FIREBASE_APP = initializeApp(FIREBASE_CONFIGS);
12-
const FIREBASE_MESSAGING = getMessaging(FIREBASE_APP);
11+
const FIREBASE_APP = FIREBASE_CONFIGS.projectId ? initializeApp(FIREBASE_CONFIGS) : null;
12+
const FIREBASE_MESSAGING = FIREBASE_APP ? getMessaging(FIREBASE_APP) : null;
1313

1414
export async function requestNotificationPermission() {
1515
try {
1616
const permission = await Notification.requestPermission();
17-
if (permission === 'granted') {
17+
if (permission === 'granted' && !!FIREBASE_MESSAGING) {
1818
const token = await getMessagingToken(FIREBASE_MESSAGING, {
1919
vapidKey: import.meta.env.VITE_FIREBASE_VAPID_KEY ?? null
2020
});
@@ -32,6 +32,7 @@ export async function requestNotificationPermission() {
3232

3333
export function onMessageListener() {
3434
return new Promise((resolve) => {
35+
if (!FIREBASE_MESSAGING) return;
3536
onMessage(FIREBASE_MESSAGING, (payload) => {
3637
resolve(payload);
3738
});

0 commit comments

Comments
 (0)