0

I have a chat app and I have implemented FCM and I can receive notifications from firebase console. How can I set it so every time user receive a new message it generates notification? This is how I'm getting my chats.

  const getLiveUpdates = () => {
    let merged_uid = uid_merger(current_user.id, chat_user.uid);
    database()
      .ref('chats/' + merged_uid)
      .orderByChild('/sendTime')
      .on('value', (msgs) => {
        if (msgs.val()) {
          setChats(Object.values(msgs.val()));
        } else {
          setChats([]);
        }
      });
  };
Aqsa Maan
  • 75
  • 1
  • 10
  • what google crawl has to do with this? – Aqsa Maan Apr 17 '21 at 07:12
  • 1
    Oops, that looks like it was another link on my clipboard. Sorry about that. This is the one you're looking for: https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens – Frank van Puffelen Apr 17 '21 at 14:54
  • I want to send them from client side – Aqsa Maan Apr 20 '21 at 17:12
  • Sending messages requires calling the FCM REST API, which require that you specify the FCM *server** key in your code. As its name implies, this key should only be used in server-side code, or in an otherwise trusted environment. The reason for this is that anyone who has the FCM server key can send whatever message they want to all of your users. By including this key in your Android app, a malicious user can find it and you're putting your users at risk. See https://stackoverflow.com/a/37993724 for a better solution. – Frank van Puffelen Apr 20 '21 at 19:14

1 Answers1

1

Based on @FrankvanPuffelen comment, you can trigger a Cloud Function that would send FCM notifications to your users by following this Notifications guide.

Farid Shumbar
  • 1,360
  • 3
  • 10
  • for cloud functions blaze plan is required. Is there any way of trigerring notification from client side – Aqsa Maan Apr 20 '21 at 17:11