#How to remove deviceToken

1 messages · Page 1 of 1 (latest)

daring jay
#

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 @zealous verge ]

#

Hi @zealous verge 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

zealous verge
#

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?

daring jay
#

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

zealous verge
#

Ah, wasn't aware the credentials would come down with the subscriber call. That sounds like it will work perfectly then.

real doveBOT
#

@zealous verge, you just advanced to level 1!

zealous verge
#

Assuming they are stored in the channels array on the subscriber object correct?

daring jay
#

Yes