Developer Team
Developer Team

Reputation: 89

How to delete/unsubscribe old firebase fcm token when user will logouts from app in angular4

we are trying to build notification services, in our angular5 application. for that, we are using google firebase messaging service. the problem we are getting when the user logs out from the app, the token is not refreshing or app is not unsubscribing, so when a new user logs in and subscribe to the new token.

please help to delete/unsubscribe token in angular5.

code to subscribe token.

this.messaging.getToken().then(function(this, currentToken ) {
      if (currentToken) {
        console.log(' token alredy have for this app port domain in browser current stored token no need to create and send new token');
        console.log(currentToken);
        } else {
        // Show permission request.
        console.log('No Instance ID token available. Request permission to generate one.');
        // Show permission UI.
        new MessagingService(null, null, null, null, null, null).generateAndSendTokenToServer(fdb);
      }
    }).catch(function(err) {
      console.log('An error occurred while retrieving token. ', err);
    });
    }

Upvotes: 0

Views: 3705

Answers (1)

Aklesh Singh
Aklesh Singh

Reputation: 973

Tested this on Angular 6

deleteToken() {
this.messaging.getToken()
.then(t => this.messaging.deleteToken(t) )
.then(r => console.log(r))
.catch(e => console.error(e));  
}

After that try generating another token In my case .onTokenRefresh not gets called automatically you have to explicitly call this.messaging.getToken().then(token => console.log(token ${token})) to generate new token.

And make sure user had already accepted request to generate token

Upvotes: 1

Related Questions