I have used Webpack to create a module bundle for Firebase Messaging for Web (javascript).
I have everything working correctly except I can't seem to implement the "subscribeToTopic" function. I followed the instructions on the site here , but when I export and run it I get "TypeError: n.subscribeToTopic is not a function".
I suspect I need to include another import for subscribeToToken, but the documentation doesn't tell me. Does anyone know what I can do?
import { initializeApp } from "firebase/app";
import { getMessaging, getToken, isSupported } from "firebase/messaging";
const firebaseApp = initializeApp({
//all the info here
});
const messaging = getMessaging(firebaseApp);
getToken(messaging, { vapidKey: 'thekeyhere' }).then((currentToken) => {
if (currentToken) {
//test - immediately subscribe token to test topic
messaging.subscribeToTopic(currentToken, topic);
}else{
console.log('need to get new token...');
}
})
.catch((error) => {
console.log('issupported was false:', error);
});