N
Novu•10mo ago
Poison

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
sumitsaurabh927
sumitsaurabh927•10mo ago
Is this related to FCM? @Poison
Poison
PoisonOP•10mo ago
yes I use fcm tokens for both android and ios
sumitsaurabh927
sumitsaurabh927•10mo ago
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?
Poison
PoisonOP•10mo ago
yes that would be great!
sumitsaurabh927
sumitsaurabh927•10mo ago
give me a few mins Check this removing stale tokens from the FCM docs
Poison
PoisonOP•10mo ago
cool, but I assume this wont remove the stale tokens from the novu user?
No description
sumitsaurabh927
sumitsaurabh927•10mo ago
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
Poison
PoisonOP•10mo ago
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
Novu_Bot
Novu_Bot•10mo ago
@Poison, you just advanced to level 1!
Poison
PoisonOP•10mo ago
Thanks
sumitsaurabh927
sumitsaurabh927•10mo ago
sure, anytime!
Mal Curtis
Mal Curtis•10mo ago
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.
sumitsaurabh927
sumitsaurabh927•10mo ago
Interesting, let me get back to you!
Pawan Jain
Pawan Jain•10mo ago
@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 🙂
Mal Curtis
Mal Curtis•10mo ago
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.
Want results from more Discord servers?
Add your server