'How to determine if FCM token is from the same device?

Question: On a server side, given a Firebase Cloud Messaging Token (only the token), is there a way to determine that I already have a token for this specific device?

I got 3 tokens from my device, that all have the same prefix (before the colon) eWckfbcqTjC9Nxm_BT8alU:APA91bHjsrbm27Qrm...
eWckfbcqTjC9Nxm_BT8alU:APA91bH1_COORkdVi...
eWckfbcqTjC9Nxm_BT8alU:APA91bGleAJmFgq4F...

Tokens from different device have completely different prefix.

Is it safe to assume, that if the prefix is the same, then the device is the same?

Situation: I have a method that accepts a CompanyID and a FCM Token to be bound to the company. Problem is, the app sends a new token rather frequently while deleting the old one only on app's side.

  1. If I just add this token (insert into) to the DB, I'll get lots of FCM error messages while sending push notifications (NotRegistered in old version and Requested entity was not found in the new version).
  2. But if I replace the token (update ... set Token = NewToken where CompanyID = CompanyID), it will make another device (that has logged in the same company account) unable to get notifications anymore.

I'm somewhat OK with the first solution, but it will result in 90% dead (but I don't know that on the server side) \ 10% alive tokens for any CompanyID in the database in just over a month.

The idea is to check all the tokens for the given CompanyID, determine if any of them shares the same device with the recieved token and if it is, replace it. Otherwise - add new.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source