How to detect and delete stale/invalid device tokens
What are the best practices when it comes to remove stale device tokens from the device token list
15 Replies
Is this related to FCM?
@Poison
yes I use fcm tokens for both android and ios
Two of the best practices, I've read about are:
- having an inactivity threshold, and
- having an automatic clean up process
Do you want any resources on this?
yes that would be great!
cool, but I assume this wont remove the stale tokens from the novu user?
no, I thought you wanted to remove from FCM
1 minute
I think this same method can be used to update the credentials of a subscriber. You can pass an array with new tokens to update the subscriber and the old ones should be replaced with the new ones I believe.
Try logging the response and confirming it
yeah I think i'll need to have a similar cron job to go to each token and check if it's expired and delete it
@Poison, you just advanced to level 1!
Thanks
sure, anytime!
I came in to ask the same question. This does not appear to be true, I always add via
deviceTokens: [token]
and the returned subscriber object contains all tokens ever added.Interesting, let me get back to you!
@Mal Curtis and @Poison
Update subscriber credentials api and setCredentials method in nodejs sdk appends a new token in
deviceTokens
array.
We have unique check in place to store only unique tokens.
To remove one/multiple tokens from subscriber credentials check out how to remove token docs section.
Let me know if you face any issue 🙂Thanks @Pawan Jain . The issue I see is that sometimes the device token in a browser is a new token, but we have no record of what token that browser originally used. So we can either a. delete all tokens - thus removing tokens from devices that should be receiving notifications, or b. leave invalid tokens on the user which just fail on every push notification. Is there a third method I can't see here? Perhaps storing a device token in local storage so we can check if it has changed? I'm not sure how reliable this would be.