Skip to content

Commit 41c136d

Browse files
fix: Replace the deprecated function for sending notification (#2185)
Co-authored-by: Vinit khandal <111434418+vinit717@users.noreply.github.com>
1 parent 29122bb commit 41c136d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

controllers/notify.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const admin = require("firebase-admin");
1+
const { getMessaging } = require("firebase-admin/messaging");
22
const { getFcmTokenFromUserId } = require("../services/getFcmTokenFromUserId");
33
const { getUserIdsFromRoleId } = require("../services/getUserIdsFromRoleId");
44

@@ -56,6 +56,7 @@ const notifyController = async (req, res) => {
5656
},
5757
tokens: Array.from(setOfFcmTokens),
5858
};
59+
5960
function calculateMessageSize(message) {
6061
const byteArray = new TextEncoder().encode(message);
6162

@@ -68,9 +69,9 @@ const notifyController = async (req, res) => {
6869
if (calculateMessageSize(message) >= 2) {
6970
res.error(401).send("Message length exceeds");
7071
}
71-
admin
72-
.messaging()
73-
.sendMulticast(message)
72+
73+
getMessaging()
74+
.sendEachForMulticast(message)
7475
.then(() => res.status(200).json({ status: 200, message: "User notified successfully" }))
7576
.catch((error) => {
7677
logger.error("Error sending message:", error);

0 commit comments

Comments
 (0)