forked from HugoByte/aurras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
40 lines (31 loc) · 1.11 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable */
import { initializeApp } from "firebase/app";
import { getMessaging, onBackgroundMessage } from "firebase/messaging/sw";
const ignored = self.__WB_MANIFEST;
const app = initializeApp({
apiKey: "AIzaSyBFKOWwoGtoPXye_S_tWQHVtOzA_mf874o",
authDomain: "aurras.firebaseapp.com",
projectId: "aurras",
storageBucket: "aurras.appspot.com",
messagingSenderId: "513296427653",
appId: "1:513296427653:web:b753ed51e3f52588e7d7ec",
measurementId: "G-555C15PTHS"
});
const messaging = getMessaging(app);
onBackgroundMessage(messaging, (payload) => {
const { title, body, icon, ...restPayload } = payload.data;
const notificationOptions = {
body,
icon: icon || '/icons/firebase-logo.png',
data: restPayload,
};
return self.registration.showNotification(title, notificationOptions);
});
self.addEventListener('notificationclick', (event) => {
if (event.notification.data && event.notification.data.click_action) {
self.clients.openWindow(event.notification.data.click_action);
} else {
self.clients.openWindow(event.currentTarget.origin);
}
event.notification.close();
});