Reputation: 506
Hello I have been trying to search on the web for a way to send a push notification using firebase from a website(javascript) to android devices. But all i've found was PHP examples. If you know a tutorial or documentation to do it using Javascript please share
Upvotes: 0
Views: 831
Reputation: 598603
You cannot securely send FCM messages directly from a web site.
Sending messages using FCM requires that you specify the so-called Server Key of your project. As its name implies, this key should only be used on servers or otherwise trusted environments, such as Cloud Functions.
One way to accomplish your use-case is to implement Cloud Functions for Firebase to actually call FCM. Then the JavaScript in your web page can call Cloud Functions, and the JavaScript in Cloud Functions can use the server key to securely call FCM. This is such a common scenario that there's even support for it in the Firebase Admin SDK for Node.js, which you can use on Cloud Functions. Some related samples can be found in the use-cases for Cloud Functions.
Upvotes: 2