Flutterfire: [firebase_message] onTokenRefresh being called every time the app loads

Created on 16 Jan 2020  路  6Comments  路  Source: FirebaseExtended/flutterfire

Describe the bug
onTokenRefresh being called every time the app loads even the tokens are the same

To Reproduce
_firebaseMessaging.onTokenRefresh.listen((token) => _saveToken(token)); // save token when it was refreshed

Expected behavior
only fire when token is refreshed

Additional context
firebase_messaging: ^6.0.3

messaging bug

Most helpful comment

Still not fixed.

You can workaround by storing token local and compare to ignore in case it is the same

However this is not the expected behavior we need the library fix.

All 6 comments

Still not fixed.

Still not fixed.

You can workaround by storing token local and compare to ignore in case it is the same

Still not fixed.

You can workaround by storing token local and compare to ignore in case it is the same

Yeah, this is exactly what did it :) thanks!

Still not fixed.

You can workaround by storing token local and compare to ignore in case it is the same

However this is not the expected behavior we need the library fix.

Is there any upcoming fix? This is quite disappointing.

@xJon You can do workaround, something like this:

Stream<String> fcmStream = instance.onTokenRefresh.distinct();

fcmStream.listen((token) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String fcmToken = prefs.getString('fcm_token');

  if (fcmToken == token) return;

  // ...
  // create new token below and save it in SharedPreferences
  // ...
});
Was this page helpful?
0 / 5 - 0 ratings