Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dynamic config for firebase messaging inside service worker #333

Open
Ashish50514561 opened this issue Sep 21, 2023 · 0 comments
Open

Comments

@Ashish50514561
Copy link

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);
})
);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant