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
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 requirementThanks 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?
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
Ah, wasn't aware the credentials would come down with the subscriber call. That sounds like it will work perfectly then.
@jarredwitt, you just advanced to level 1!
Assuming they are stored in the channels array on the subscriber object correct?
Yes