sowdri
sowdri

Reputation: 2243

Firebase Auth + FCM

My usecase it to send a push-notification to a user using the Firebase Auth UID to all the devices he is signed-in. Since firebase Auth is managing the user sessions,

  1. Is there a way to directly send a FCM notification just using the uid of the user? Or
  2. Is there a way to fetch the registration ids of all signed-in devices for a given uid?

This looks like standard requirement, for example to update the 'Order Status' to a user. If available this could be pretty powerful, and could greatly simplify direct messaging requirements (e-commerce, chat etc) where the user gets notified on web/android/ios.

If this is not possible, any suggestions on the standard way to acquire/manage the registrations_ids of a given user is appreciated.

Thanks all,

Upvotes: 3

Views: 1183

Answers (1)

bojeil
bojeil

Reputation: 30868

This is not supported out of the box but you can build the mechanism. You need to maintain a uid specific deviceGroup and all the registration ID per device that belongs to it.

Each time a user signs in with Firebase, you get the device registration ID and the user's ID token and send it to your backend. You verify the ID token and get the uid from it, you then add that registration ID to that user's device group.

Each time a user signs out, you remove their registration ID from the signed out user's device group.

When you want to send a push notification to a specified user, you can send it to the user's device group ID.

This is the simplified version but there are a bunch of edge cases you have to deal with to keep the device group for a user in sync so no notification is sent to a signed out user.

Upvotes: 3

Related Questions