N
Novu16mo ago
Pawan Jain

How to remove deviceToken

Is there any ability to remove a subscriber's credential once it's been set? Our use case is that our push tokens are linked to a specific login session since our users can use multiple devices. When a user logs out of that device we need the ability to remove a device's push token from one subscriber and add it to the next subscriber that logs in. [asked by @jarredwitt ]
8 Replies
Pawan Jain
Pawan Jain16mo ago
Hi @jarredwitt you can achieve like this:- First remove from first subscriber await novu.subscribers.setCredentials('subscriberId1', PushProviderIdEnum.EXPO, { deviceTokens: [], }); Now add to second second subscriber await novu.subscribers.setCredentials('subscriberId2', PushProviderIdEnum.EXPO, { deviceTokens: ['token1'], }); you can change EXPO to FCM as per your requirement
jarredwitt
jarredwitt16mo ago
Thanks for the speedy reply! What if there are multiple deviceTokens registered for the subscriber? It's an edge case for us, but a user could be using an iPad and an iPhone and need notifications to both. Is there a way to remove a specific token?
Pawan Jain
Pawan Jain16mo ago
get the subscriber first using subscriberId1 novu.subscribers.get('subscriberId1') you will get all details of subscriber, create a new variable and store all tokens except that specific token, by using JS array filter method. now again store tokens using novu.subscribers.setCredentials
jarredwitt
jarredwitt16mo ago
Ah, wasn't aware the credentials would come down with the subscriber call. That sounds like it will work perfectly then.
Novu_Bot
Novu_Bot16mo ago
@jarredwitt, you just advanced to level 1!
jarredwitt
jarredwitt16mo ago
Assuming they are stored in the channels array on the subscriber object correct?
Pawan Jain
Pawan Jain16mo ago
Yes