0

I have both my web app and my android app included into my firebase project. Using the web app, the user can insert data into the realtime database. Using the android app, the user can view his record, which is read from the realtime database.

My javascript:

firebase.database().ref("db/0/").push(
    {
        "name":"XXXX",
        "age":YY,
        "address":"ABCDEF"
    }
)

//I want to send a notification to the app, whenever a new data is pushed

I want to send a notification to the app, whenever a new data is pushed into the realtime database. How do I proceed?

1 Answers1

0

Calls to the FCM REST API to send a message to a device 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 or web app, a malicious user can find it and you're putting your users at risk.

See How to send one to one message using Firebase Messaging for a better solution, which also links to the Firebase documentation of using Cloud Functions to notify a usr when something relevant to them happens in the Realtime Database.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807