2

Is a firebase token ID based on the device's characteristics, such as IMEI for phones, MAC for PC, etc.. ?

My primary concern is the following:

Multiple users use a given device to access the same app ( Think FB ).

  1. User 1 logs to the app and Firebase provides a token ( E.g. FirebaseInstanceId.getInstance().getInstanceId() ).
  2. User 1 does a logout
  3. User 2 logs in.
  4. Is the same Firebase registration token from #1 going to be used now for User 2?

Is a new firebase ID generated for User 2 or is this something that needs to be handled manually by the app itself? I have the feeling that this is more a responsibility of the app developer where they monitor who logs in and so forth and the old registration ID is cancelled while a new one is generated for this new login ?

Just to clarify - I only use Firebase Cloud Messaging and nothing else from Firebase so I will be managing the notifications from my own server. This means that I will be storing the Firebase registration IDs in my own database to know for which Firebase Registration ID to generate a notification (e.g. user receives a message from another user), for example.

AndFantasy
  • 73
  • 1
  • 10
  • There is no inherent relation between an FCM/Instance ID token and a user. If you need such a relation, you'll need to maintain it yourself. A typical approach could be to associate a token with a user (in addition to associating a user with a token). Then when a new user signs in to the app in the same device, associate that user with the token. Also see my answer here: https://stackoverflow.com/questions/45386448/when-to-register-an-fcm-token-for-a-user/45390368#45390368 – Frank van Puffelen Jul 22 '18 at 21:26
  • 1
    @FrankvanPuffelen, thanks for the info.This is what I was thinking would be the case since it made a lot of sense from Firebases's point of view. – AndFantasy Jul 23 '18 at 01:04

1 Answers1

6

According to the Firebase Docs:

The registration token may change when:

  • The app deletes Instance ID
  • The app is restored on a new device
  • The user uninstalls/reinstall the app
  • The user clears app data.

This means the token won't change when user 1 logs out. A work-around would be calling deleteInstanceId() on user log out. This will delete the current Instance ID and a new Instance ID will be generated asynchronously if Firebase Cloud Messaging auto-init is enabled.

Please note that the docs also mention this is a blocking function so do not call it on the main thread.