-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#257] 알림 허용 안 할 시 fcm토큰 발급 요청 안되도록 수정
- Loading branch information
Showing
4 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { messaging } from "@/firebase"; | ||
import { getToken, onMessage } from "firebase/messaging"; | ||
|
||
async function getNotificationPermission() { | ||
console.log("권한 요청 중..."); | ||
|
||
const permission = await Notification.requestPermission(); | ||
if (permission === "denied") { | ||
console.log("알림 권한 허용 안됨"); | ||
return; | ||
} | ||
|
||
console.log("알림 권한이 허용됨"); | ||
|
||
const fcmToken = await getToken(messaging, { | ||
vapidKey: import.meta.env.VITE_FIREBASE_VAPID, | ||
}); | ||
|
||
if (fcmToken) console.log("token: ", fcmToken); | ||
else console.log("Can not get Token"); | ||
|
||
onMessage(messaging, (payload) => { | ||
console.log("메시지가 도착했습니다.", payload); | ||
}); | ||
|
||
return fcmToken; | ||
} | ||
|
||
export default getNotificationPermission; |