fix: error send notification
Deskripsi: - fix send web notification > empty array - console.log xsendmany firebase notification - upd version app No Issues
This commit is contained in:
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "1.7.4", tahap: "beta", update: "-api mobile; -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi" }, { status: 200 });
|
return NextResponse.json({ success: true, version: "1.7.5", tahap: "beta", update: "-api mobile; -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -8,23 +8,27 @@ WibuServerPush.init({
|
|||||||
|
|
||||||
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
export async function funSendWebPush({ sub, message }: { sub: { idUser: string, subscription: string }[], message: { body: string, title: string } }) {
|
||||||
try {
|
try {
|
||||||
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
if (sub.length > 0) {
|
||||||
|
const subs: PushSubscription[] = sub.map((v) => JSON.parse(v.subscription)) as PushSubscription[]
|
||||||
|
|
||||||
const kirim = await WibuServerPush.sendMany({
|
const kirim = await WibuServerPush.sendMany({
|
||||||
subscriptions: subs as any,
|
subscriptions: subs as any,
|
||||||
data: {
|
data: {
|
||||||
body: message.body,
|
body: message.body,
|
||||||
title: message.title,
|
title: message.title,
|
||||||
link: "/home?cat=notification",
|
link: "/home?cat=notification",
|
||||||
variant: "notification"
|
variant: "notification"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (kirim) {
|
||||||
|
return { success: true, message: "Berhasil mengirim notifikasi" }
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
if (kirim) {
|
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||||
return { success: true, message: "Berhasil mengirim notifikasi" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
return { success: true, message: "Berhasil mengirim notifikasi [0]" }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Send web push notification error", error);
|
console.error("Send web push notification error", error);
|
||||||
return { success: false, message: "Gagal mengirim notifikasi" }
|
return { success: false, message: "Gagal mengirim notifikasi" }
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
console.log("masuk", token.length, token)
|
||||||
|
|
||||||
if (token.length > 0) {
|
if (token.length > 0) {
|
||||||
|
console.log("Token", token.length)
|
||||||
// Kirim pesan
|
// Kirim pesan
|
||||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||||
if (response.failureCount > 0) {
|
if (response.failureCount > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user