From 20032301e8c9701eff66905ab7b9636693691704 Mon Sep 17 00:00:00 2001 From: amal Date: Thu, 21 Aug 2025 15:31:27 +0800 Subject: [PATCH] fix : firebase Deskripsi : - fix error emty token firebase NO Issues --- xsendMany.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/xsendMany.ts b/xsendMany.ts index a03b132..aba35aa 100644 --- a/xsendMany.ts +++ b/xsendMany.ts @@ -22,7 +22,7 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to title, body, }, - tokens:token, + tokens: token, data, android: { priority: "high", @@ -44,18 +44,22 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to }, }; - // Kirim pesan - const response = await getMessaging().sendEachForMulticast(message as any); - if (response.failureCount > 0) { - const failedTokens: any[] = []; - response.responses.forEach((resp, idx) => { - if (!resp.success) { - failedTokens.push(token[idx]); - } - }); - const del = await deleteDeviceError({ device: failedTokens }); + if (token.length > 0) { + // Kirim pesan + const response = await getMessaging().sendEachForMulticast(message as any); + if (response.failureCount > 0) { + const failedTokens: any[] = []; + response.responses.forEach((resp, idx) => { + if (!resp.success) { + failedTokens.push(token[idx]); + } + }); + const del = await deleteDeviceError({ device: failedTokens }); + } + } + return { success: true, message: "Notifikasi berhasil dikirim", }; } catch (error) { console.error("Error mengirim notifikasi:", error);