0

So i'm making an app using React JS, Cordova, node backend and a mongo database. I want to integrate firebase cloud messaging (FCM) into my platform. I'm quite new to firebase, and developing in general, and i'm not quite sure where to initialise firebase. I currently have it integrated into the front-end and it's requesting permission to receive notifications, generating tokens, and receiving messages from the firebase console. However i'm not entirely sure where to go from here. Do I add it to my backend as-well?

2 Answers2

1
  1. You have to get the FCM token from the frontend (or, client app).
  2. After getting the token, just send it to your backend server using a POST method.
  3. Then, store the token in whatever database you're using in your backend. It can be MongoDB, PostgreSQL, etc.
Shariful Islam Mubin
  • 2,146
  • 14
  • 23
1

If you can receive messages in your client app, your front-end work is done for the moment.

But to send messages programmatically, you will need to write back-end code indeed. That's because sending messages through FCM requires that you specify the FCM server key to the API, and as its name implies that key should only be used in a trusted environment, such as your development machine, a server you control, or Cloud Functions.

For more on this, have a look at:

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