push subscriptions managment
This commit is contained in:
@ -128,29 +128,32 @@ function PwaManager() {
|
||||
|
||||
try {
|
||||
e.preventDefault();
|
||||
await subscription.unsubscribe();
|
||||
// Call your API to delete or invalidate subscription data on server
|
||||
setSubscription(null);
|
||||
setIsSubscribed(false);
|
||||
if (session?.user?.id != null) {
|
||||
await fetch(`/api/notify`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ id: session?.user.id }),
|
||||
}
|
||||
).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete subscription data on server.');
|
||||
}
|
||||
else {
|
||||
console.log('Subscription data deleted on server.');
|
||||
}
|
||||
});
|
||||
if (subscription) {
|
||||
await subscription.unsubscribe();
|
||||
// Call your API to delete or invalidate subscription data on server
|
||||
setSubscription(null);
|
||||
setIsSubscribed(false);
|
||||
if (session?.user?.id != null) {
|
||||
await fetch(`/api/notify`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
//send the current subscription to be removed
|
||||
body: JSON.stringify({ id: session.user.id, subscriptionId: subscription.endpoint })
|
||||
}
|
||||
).then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete subscription data on server.');
|
||||
}
|
||||
else {
|
||||
console.log('Subscription data deleted on server.');
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log('Web push unsubscribed!');
|
||||
}
|
||||
console.log('Web push unsubscribed!');
|
||||
} catch (error) {
|
||||
console.error('Error unsubscribing from notifications:', error);
|
||||
}
|
||||
|
Reference in New Issue
Block a user