Unsubscribe from FCM

Hi!
I have a problem with FCM. I’m using Ionic with Capacitor and Firebase Cloud Messaging.
I make my code following this steps: https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase
But I want to register when the user is logged, so I put the code when the login is completed.
The notifications works very good. But I have a problem. I want to unsubscribe from FCM (delete token) when the user is log out, because I just want users logged in to receive notifications.
¿How can I do this?
Thank you very much, and sorry for my english.

The PluginListenerHandle you receive when registering an event listener has a remove method. Is this insufficient for your needs?

I’m sorry, but how can I use that? I mean, to fix it I tried with fcm-capacitor plugin (https://github.com/stewwan/capacitor-fcm). Using the method deleteInstance(), I can delete the token, but automatically a new token is generated, so I still receive notifications for the new token.

Thank you for your help!

let listener = PushNotifications.addListener(...);
...
listener.remove();
1 Like