Hello guys i'm struggling to find a solution on how to send a notification to a specific user with web-push and and serviceWorker
here's the code (working but everyone can see the notification)
server :
@Post('/notifications/subscribe')
notif(@Body() body: any) {
const subscription = body;
console.log(subscription);
globals.payload = subscription;
const payload = JSON.stringify({
email: subscription.email,
title: 'Hello!',
body: 'It workssss.',
});
webpush
.sendNotification(subscription, payload)
.then((result) => console.log(result))
.catch((e) => console.log(e.stack));
}
serviceWorker
self.addEventListener("push", (event) => {
const data = event.data.json();
const options = {
body: data.body,
};
event.waitUntil(self.registration.showNotification(data.title, options));
});