diff --git a/src/common/component/Notification/index.js b/src/common/component/Notification/index.js index 50860527..407cabe4 100644 --- a/src/common/component/Notification/index.js +++ b/src/common/component/Notification/index.js @@ -20,12 +20,13 @@ const Notification = () => { const { newPath } = event.data; navigateTo(newPath); }; - navigator.serviceWorker.addEventListener( + // https only + navigator.serviceWorker?.addEventListener( "message", handleServiceworkerMessage ); return () => { - navigator.serviceWorker.removeEventListener( + navigator.serviceWorker?.removeEventListener( "message", handleServiceworkerMessage ); diff --git a/src/common/component/Notification/useDeviceToken.js b/src/common/component/Notification/useDeviceToken.js index 4c314252..71ec92bb 100644 --- a/src/common/component/Notification/useDeviceToken.js +++ b/src/common/component/Notification/useDeviceToken.js @@ -2,9 +2,9 @@ import { useState } from "react"; import { initializeApp } from "firebase/app"; import { getToken, getMessaging } from "firebase/messaging"; import { firebaseConfig } from "../../../app/config"; -const messaging = getMessaging(initializeApp(firebaseConfig)); const useDeviceToken = (vapidKey) => { const [token, setToken] = useState(null); + const messaging = getMessaging(initializeApp(firebaseConfig)); getToken(messaging, { vapidKey,