Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native-firebase: How to delete a token at logout?

I'd like to stop receiving notifications to the app once the user logs out. I guess I'd have to remove the device token generated by react-native-firebase but I can't find any functionality to do this.

Does anyone know how to do this?

like image 267
Edoardo Foco Avatar asked May 19 '18 18:05

Edoardo Foco


2 Answers

🔥 messaging().deleteToken()

You could achieve like this:

import auth from '@react-native-firebase/auth';
import messaging from '@react-native-firebase/messaging';

auth().onAuthStateChanged(user => {
    if (!user) // Signed out
        messaging().deleteToken();
});
like image 105
shital rahane Avatar answered Sep 17 '22 16:09

shital rahane


The documentation isn't great, but I have found a working solution in v4.3.x

// login
const authorizedEntity = firebase.iid().app.options.messagingSenderId;
firebase.iid().getToken(authorizedEntity).then(token => token);

// logout
const authorizedEntity = firebase.iid().app.options.messagingSenderId;
firebase.iid().deleteToken(authorizedEntity, '*').then(nullToken => nullToken);
like image 40
Ian Brindley Avatar answered Sep 17 '22 16:09

Ian Brindley