8

Is there a way to create a registration id with scope of logged in user. I have an app which allows user to login as different user (say one user as student and other as a parent). User can switch between the users. Case is somewhat similar to gmail app where multiple email ids can be logged in at same time.

The issue is when we call

 FirebaseInstanceId.getInstance().getToken()

It will give the device id for that app instance. So if i am to target a specific user logged in i cannot.

One way i can accomplish targeting a user is to send user_id explicitly as data, which in my case is not efficient as it will take to send one FCM send request for each user. Is there anyway this can be accomplished. Would like to know how gmail is handling user specific notifications.

AL.
  • 36,815
  • 10
  • 142
  • 281
ismathullah
  • 81
  • 1
  • 4
  • 1
    Possibly related (if not duplicate or at the very least, helpful) posts: https://stackoverflow.com/a/43197589/4625829, https://stackoverflow.com/a/40589815/4625829 – AL. May 30 '17 at 10:03
  • Well, See firebase docs you don't need diffrent Token for that ,Firebase also send Topic wise Message in which you can select topics and subscribe - unsubscribe them – 9spl May 30 '17 at 10:28

1 Answers1

9

Token (reg id) is intended to represent a mobile device.

As you've said you can send in payload or in tags which user the push notification is destined to, check if it is the same as the current logged in user and decide whether to create the notification or not.

The only problem here may be, how to identify the current user if at the moment of push arrival your application is killed or all users are logged out. I think in this case the solution depends on privacy level of the pushed data.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
  • Isn't this an invitation to hack the app? If the new user does not update the token (by preventing this particular part of communication with Firestore) they would receive push notifications of the user that was previously logged in ... Is there any way to make the Cloud Function that sends the notification to check what user is currently logged in on a specific device (aka fcm token)? – Fred May 05 '23 at 14:28