Home > OS >  push notifications to list of users at specified date and time firebase and react
push notifications to list of users at specified date and time firebase and react

Time:10-21

I'm building a react and firebase app. I have a firestore database with a collection of documents for events. In each event doc I have the date and time of the event, and a list of user uids who are signed up for it. How do I send a push notification to all of them at the time of the event?

CodePudding user response:

I will explain what are steps that you should do in order to achieve this. In here I am assuming that you are sending the notification when the event is created in the firestore.

  1. You have to get the FCM token from the users and save it in the firestore (I am assuming you will save the user data in the users collection in the firestore). This can be done when user gets registered or logged in to your application.
  2. When the event document is created in the firestore, you can get the user ids and fetch the relevant user from the user collection and extract the FCM token from it.
  3. Next you can send the relevant notification to all of these FCM tokens.

In order to achieve this you could either use a cloud function firestore trigger or, do it inside the react app after you save the event document.

You can follow following firebase documentation for more details.

https://firebase.google.com/docs/cloud-messaging/js/client

https://firebase.google.com/docs/cloud-messaging/js/send-multiple#setting_notification_options_in_the_send_request

  • Related