react-swipeable
react-swipeable copied to clipboard
Use dynamic config for firebase messaging inside service worker
I am trying to initialize firebase messaging like I am able to see notifications when app is in foreground or background but when i close the app i don't get the notifications. Also when i relaunch the app i don't see any notifications ,Help me out please
self.addEventListener("install", (event) => {
event.waitUntil(
fetch(http://localhost:3000/api/8414f66c-f30f-4283-962d-3fc6ee0dfb5c/org
)
.then((response) => response.json())
.then((config) => {
console.log("cCCCCCCCCCConfig", { config });
// Initialize Firebase with the fetched configuration
firebase.initializeApp(config);
// Continue with the rest of your service worker setup
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
console.log(
"[firebase-messaging-sw.js] Received background message ",
payload
);
// Customize notification here
const notificationTitle = "Background Message Title";
const notificationOptions = {
body: "Background Message body.",
icon: "/firebase-logo.png",
};
self.registration.showNotification(
notificationTitle,
notificationOptions
);
});
}) .catch((error) => { console.error("Error fetching Firebase configuration:", error); }) ); });