Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Firebase Cloud Messaging Token in Flutter

When One user A log In and then Log out. Then user B logs In. The notification intended for user A is received bu user B because the token generated for user A is not removed. The dart package have no options for removing this token.

like image 691
Nishant Subedi Avatar asked Nov 01 '18 08:11

Nishant Subedi


People also ask

How do I refresh FCM token flutter?

FirebaseMessaging _firebaseMessaging = new FirebaseMessaging(); _firebaseMessaging. configure( onMessage: (Map<String, dynamic> message) { }, onResume: (Map<String, dynamic> message) { }, onLaunch: (Map<String, dynamic> message) { }, ); _firebaseMessaging. getToken(). then((token) { saveToken(token); });

How do I get firebase messaging token flutter?

Access the registration token To retrieve the current registration token for an app instance, call getToken() . If notification permission has not been granted, this method will ask the user for notification permissions.

Can you change firebase tokens?

Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens. Refresh tokens expire only when one of the following occurs: The user is deleted. The user is disabled.


1 Answers

You can accomplish that by calling deleteInstanceID. Be aware that deleteInstanceID automatically recreates the token, so you have to setAutoInitEnabled to false beforehand. You can check the current auto-init value by querying autoInitEnabled.

Note: requires firebase_messaging version 2.1.0 or greater.

like image 176
Feu Avatar answered Sep 21 '22 16:09

Feu