28 lines
773 B
JavaScript
28 lines
773 B
JavaScript
import admin from "firebase-admin";
|
|
import serviceAccount from "../googlefirebasePushnotification.json" with { type: "json" };
|
|
export const sendPushNotification = async (userToken, message) => {
|
|
// const admin = require("firebase-admin");
|
|
// const serviceAccount = require("./path/to/your-firebase-adminsdk.json");
|
|
|
|
if (!admin.apps.length) {
|
|
admin.initializeApp({
|
|
credential: admin.credential.cert(serviceAccount),
|
|
});
|
|
}
|
|
|
|
const payload = {
|
|
notification: {
|
|
title: "KYC Rejected ",
|
|
body: message,
|
|
},
|
|
token: userToken
|
|
};
|
|
|
|
try {
|
|
const response = await admin.messaging().send(message);
|
|
console.log("Successfully sent message:", response);
|
|
} catch (error) {
|
|
console.error("Error sending message:", error);
|
|
}
|
|
};
|