arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

onTokenRefresh() is triggered every time the app is opened #998

Open uncvrd opened 5 years ago

uncvrd commented 5 years ago

Describe the bug If my understanding is correct, onTokenRefresh() should only be called when a new token is generated. However, while testing on iOS, this method observable is being called every time I close and reopen the application. It doesnt run the token method if I go from App -> Home Screen -> App. But if I go App -> Swipe to close app -> Reopen application then it runs (but it's still the same token instance). I thought this method should only run if the instance token actually needs to be changed?

I've confirmed that the token is not updating by comparing the token instance ID that is printed to XCode console to the one that is currently saved in my database.

To Reproduce Steps to reproduce the behavior:

In my app.component.ts I subscribe to an auth method from firebase that returns a user object

this.auth.user$.subscribe(
        (user) => {
          if (user) {
            this.fcm.getToken(user)
          }
      })

in my fcm.service I then subscribe to the onTokenRefresh():

import { Firebase } from '@ionic-native/firebase/ngx';
constructor(public firebaseNative: Firebase) { }

  async getToken(user) {
    this.firebaseNative.onTokenRefresh().subscribe((instanceToken) => {
      alert('Token has been refreshed')
    })
    ...
  }

And every time I open my application, the Token has been refreshed text is printed to the alert.

Here's a video, every time I close out the app and reopen, the token is printed as an alert notice how the token is the exact same on each one but for some reason even though it's the same token that onTokenRefresh is being called..:

https://streamable.com/xawbe

Expected behavior Token refresh method should only be triggered when a new token instance is generated. Such as when I'm deleting and reinstalling my app.

Screenshots token instance shown in Xcode console:

screen shot 2019-02-05 at 1 12 01 pm

token instance in my database:

screen shot 2019-02-05 at 1 14 40 pm

Plugin Version Run cordova plugin list to find out what version of cordova-plugin-firebase you are running with

cordova-plugin-firebase 2.0.5 "Google Firebase Plugin"

Desktop (please complete the following information):

Smartphone (please complete the following information):

harshgrovr commented 5 years ago

I am facing same issue. Please help!