'Trying to use FCM with wordpress/php

I am struggling to understand how to implement this, so any guides/help would be appreciated!

I want to use FCM in my php/wordpress site. As I understand it I need to get subscriptions and save them in the database and then use that token I saved to send to users. Although ideally I'd like to only use groups. So when someone accepts notifications they gets saved to a topic named: "all" or something. And then when a new post is posted I want to be able to send notifications to all the users.

Problem is that now, when I prompt the user to subscribe I am unable to retrieve token because it can't register the firebase-messaging-sw.js because I already have another sw registered.

I also imported firebase with npm, but I cant import it via " import { initializeApp } from "firebase/app";" because it says "Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../"."

But I can use cdn imports.

I am sorry if this post is not very coherent, I am trying to formulate it as best as I can.

1.What is the best way to go about subscribing users to a specific topic, do I even need to save a token to the database for that? 2. Can I use another sw instead of firebase's service worker? Or should I merge my other sw with firebase's service worker? 3. How can I solve that import issue described above?

any help at all would be very appreciative, documentation I cant seem to find on my own would be hugely appreciated. (I feel as though I've read them all but probably I am just missing something obvious)

Regards Sonny



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source