I am using firebase javascript api v9 in my react project and i am using the code below as suggested by the oficial documentation
import { getMessaging } from "firebase/messaging";
// These registration tokens come from the client FCM SDKs.
const registrationTokens = [
'fcm_token_string'
];
// Subscribe the devices corresponding to the registration tokens to the topic
getMessaging().subscribeToTopic(registrationTokens, topic)
.then((response) => {
// See the MessagingTopicManagementResponse reference documentation [enter link description here][1]for the contents of response.
console.log('Successfully subscribed to topic:', response);
})
.catch((error) => {
console.log('Error subscribing to topic:', error);
});
However, despite of doing exactly what the documation of firebase api v9 says, I am getting undefined when accessing getMessaging().subscribeToTopic function.
I am wondering if this function was moved to another component and the documentation has become outdated.
I would appreciate any help. Thank you in advance.