Nishant Subedi
Nishant Subedi

Reputation: 151

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.

Upvotes: 12

Views: 9202

Answers (2)

Feu
Feu

Reputation: 5780

EDIT: looks like deleteInstanceID was deprecated in favor of deleteToken. Please look the other answer for more info.


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.

Upvotes: 11

AnasSafi
AnasSafi

Reputation: 6224

Note from Official documentation:

DEPRECATED: deleteInstanceID() has been deprecated in favor of deleteToken()

So to make current token invalid just add this code to your logout function:

await FirebaseMessaging.instance.deleteToken();

After that, messages sent by the server to this token will fail.

Upvotes: 13

Related Questions