skip to Main Content

I have a notification problem with Firebase_messaging connected to Flutter.

I have the notification that works when I log in to my account.  The problem is if I switch accounts, I get the notifications from the old account.

I would like Firebase_messaging Flutter to disconnect the token from the phone if I disconnect the account.

Do you have a solution?
How can I check the account token every time I go to the home_page?

Ps: I have also tried clearing my app’s cache and storage but the problem persists

2

Answers


  1. Chosen as BEST ANSWER

    Thanks @Yuji Bry.

    So I did this personally:

    • For disconnection :

    Future deleteToken() { return FirebaseMessaging.instance.deleteToken(); }

    • For connection :

    NotificationService.getToken().then((value) { DatabaseService(userCredential.user!.uid).saveToken(value); });

    PS : For the connection I have to do like this for the moment because personally the "onTokenRefresh" does not work for me. The token therefore changes with each connection (so if 2 phones are connected to the same account, only the last phone that knows connected to the account will have the notifications)


  2. You need to remove the current token using deleteToken() whenever a user logs out. This will invalidate the token associated to the old user. Then, make sure to generate a new one after a new user logs in.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search