I have a ReactJS and React Native apps connected to the same back-end (firebase), and I've set up everything on the mobile app to receive a notification that is triggered from the React app, however, I'm unable to trigger the Cloud Messaging API from the React App, according to the documentation there are 2 ways, Firebase Admin SDK and REST API, but Firebase Admin isn't working because apparently it can't be used on the client side code, and I have no knowledge in REST API, or how it works in React, I tried searching for an example code but didn't find anything.
Asked
Active
Viewed 37 times
1 Answers
1
It is not possible to securely send messages directly from one client to an other with Firebase Cloud Messaging.
Sending messages through Firebase Cloud Messaging requires that you specify the FCM server key or specify the administrative credentials for the project. Both of these can only securely be done on a trusted environment, such as your development machine, a server that you control, or something like Cloud Functions/Cloud Run.
Also see:

Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
Can do this using a Callable Cloud Function that I can call from my client side with the appropriate data passed? If so that would be great, and do you have any article that can help me do it? – Dan Tobmson Jul 24 '23 at 08:09
-
Can I use the Firebase Admin SDK with Cloud Functions? Will it be possible in a ReactJs app? – Dan Tobmson Jul 24 '23 at 08:10
-
Yes, a callable Cloud Function would be a valid option, but so would any other type of cloud function or the other options I mentioned. For one example, see https://github.com/firebase/functions-samples/tree/main/Node-1st-gen/fcm-notifications, but there's probably many more. If you can't get that to work, I recommend posting a new question with a [minimal repro](http://stackoverflow.com/help/mcve) of where you got stuck. --- Also see [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – Frank van Puffelen Jul 24 '23 at 13:47
-
I was actually able to do it through Callable Cloud Functions, and it's working perfectly, thanks for the tips :) – Dan Tobmson Jul 24 '23 at 14:15