Turan Bicav
Turan Bicav

Reputation: 5

How do I send notification to button with React native firebase cloud message?

I have a post page, and this page will have a button when the correct answer to the question asked in the post is given, just like in stackoverflow, and when this button is pressed, I want the people who follow this post to be notified. I want to send notifications using a react native cloud message.

Upvotes: 0

Views: 470

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598847

Calls to the Firebase Cloud Messaging API to send a message 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. For this reason it is not possible to send a message directly from one device to another device/user through FCM, the messages must always be sent from a trusted environment.

The common approach is to create a custom server-side endpoint/API (using Cloud Functions, or a server that you control) that makes the FCM call on the user's behalf, and then call that endpoint from within your React Native app. For an example of this, see use-case notifying users when something interesting happens in the Firebase documentation.

Upvotes: 1

Related Questions