i'm using react-native with android
I want to use push notifications using React native and firebase fcm
In the official firebase document, admin is used to send message to the device, but instead of admin, I want to send it to the device using rest api.
But I am confused how to use the rest api to request a message The official documentation says to use rest api as follows
https://fcm.googleapis.com/fcm/send
this is my code
(backend)
router.post('/:postId/comment', isLoggedIn, async (req, res, next) => { // POST /post/1/comment
try {
await admin.messaging().sendToDevice(
ownertoken.fcmtoken, // ['token_1', 'token_2', ...]
{
data: {
owner: JSON.stringify(owner),
user: JSON.stringify(user),
},
},
{
priority: 'high',
},
);
(front)
import {AppRegistry} from 'react-native';
import Root from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';
messaging().setBackgroundMessageHandler(async remoteMessage => {
const owner = JSON.parse(remoteMessage.data.owner);
const user = JSON.parse(remoteMessage.data.user);
console.log(`The user "${user.name}" comment your post`);
});
AppRegistry.registerComponent(appName, () => Root);
in backend router
How can I send a message to the front device using the rest api instead of admin?