From 4f16836094bde40abd6618d35f14b37d147869b3 Mon Sep 17 00:00:00 2001 From: jnkeniaem Date: Thu, 28 Nov 2024 17:39:13 +0900 Subject: [PATCH] =?UTF-8?q?[FE]=20FIX:=20=EB=B9=84=EB=8F=99=EA=B8=B0?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=ED=98=B8=EC=B6=9C=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EC=A0=9C=EC=96=B4=20#1714?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cabinet/firebase/firebase-messaging-sw.ts | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/frontend/src/Cabinet/firebase/firebase-messaging-sw.ts b/frontend/src/Cabinet/firebase/firebase-messaging-sw.ts index fdab56028..0ae509564 100644 --- a/frontend/src/Cabinet/firebase/firebase-messaging-sw.ts +++ b/frontend/src/Cabinet/firebase/firebase-messaging-sw.ts @@ -21,26 +21,16 @@ export const firebaseConfig = { const app = initializeApp(firebaseConfig); let messaging: null | Messaging = null; -let isApiSupported = false; - -// NOTE : 사용자 브라우저가 푸시 알림 기능을 지원하는지 확인 -isSupported().then((result) => { - isApiSupported = result; - if ( - typeof window !== "undefined" && - typeof window.navigator !== "undefined" && - isApiSupported - ) { - messaging = getMessaging(app); - } -}); - const unsupportedMsg = `사용 중인 환경에서는 푸시 알림 기능이 지원되지 않습니다. 데스크탑 이용을 권장드립니다.`; -const checkBrowserSupport = () => { - if (!isApiSupported) { +// NOTE : 사용자 브라우저가 푸시 알림 기능을 지원하는지 확인 +const checkBrowserSupport = async () => { + const isApiSupported = await isSupported(); + + if (isApiSupported) messaging = getMessaging(app); + else { let error = new Error(unsupportedMsg); error.name = "브라우저 알림 지원 제한"; throw error; @@ -49,7 +39,7 @@ const checkBrowserSupport = () => { // FCM APP을 등록 후 브라우저 알림 권한을 요청하고, 토큰을 반환 export const requestFcmAndGetDeviceToken = async (): Promise => { - checkBrowserSupport(); + await checkBrowserSupport(); console.log("권한 요청 중..."); const permission = await Notification.requestPermission(); @@ -77,7 +67,7 @@ export const requestFcmAndGetDeviceToken = async (): Promise => { // FCM 토큰 제거 및 브라우저 알람 권한 해제 export const deleteFcmToken = async (): Promise => { - checkBrowserSupport(); + await checkBrowserSupport(); await deleteToken(messaging!); console.log("Token deleted.");