smartnav / fcm-notification

Push notificaton for ios and android
25 stars 13 forks source link

Hey Is there a way i can add server key in the request #16

Closed k2209 closed 1 year ago

k2209 commented 1 year ago

const admin = require('firebase-admin')
const fcm = require('fcm-notification')

// For Notification
const serviceAccount = require('../../firebase/push-notification-key.json')

const certPath = admin.credential.cert(serviceAccount)
//here goes my server key
const FCM = new fcm(certPath, { legacyServerKey: config.FIREBASE_SERVER_KEY }))

const Helper = {}

Helper.pushNotification = async (notificationTitle, notificationBody, notificationData, fcm_token) => {

  try {
    let message = {
      notification: {
        title: notificationTitle,
        body: notificationBody
      },
      data: {productId: notificationData},
      token: fcm_token
    }

    FCM.send(message, (err) => {
      if (err) {
        return err
      }
      else {
        return err
      }
    })
  } catch (err) {
    return err
  }

}
```  this is my code