Unique device id and Push Tokens changing

We are using Ionic 5 (Angular) with capacitor PushNotifications set up using Firebase FCM.

Currently, on successful login to our app we call:

PushNotifications.requestPermission().then( if granted => PushNotifications.register() )

and have the event listeners set up e.g. for “registration”.

In that event callback, I retrieve device info using the Device plugin

Device.getInfo()

and, coupled with the registered Push Token and some other user info, call into our backend token management system to register the device.

This all works lovely, but has issues:

  1. deviceUuid from getInfo() can change depending on device os and make model
  2. on some devices, some OS, it can change when app is updated, or uninstalled and re-installed, or if developer runs app from XCode or Android Studio via USB debugging, or if they clear their local storage data
  3. calling register() for Push a second time can sometimes return the same Token for a device but have seen it return a different token.
  4. our app can allow user to login as different users on the same device so again this would need separate tokens per user id

All these issues make the job of managing Push Tokens and devices on our back-end platform extremely challenging as we’ve seen the same device registered multiple times for the same user, but with different Push Tokens and/or different device Uuids.

This must be a common problem but I’ve yet to find a reliable, consistent solution.

What’s the best practice approach for managing this?

Any feedback and help much appreciated :slight_smile: