From 14f665ddf090127e2cc0e0da9550a0e3c87ed7df Mon Sep 17 00:00:00 2001 From: zerosoul Date: Sun, 5 Jun 2022 13:03:21 +0800 Subject: [PATCH] fix: deployment error in http --- src/common/component/Notification/index.js | 5 +++-- src/common/component/Notification/useDeviceToken.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) 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,