fix(webpush): only remove the current browser's subscription

Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
0xsysr3ll
2025-12-08 22:05:53 +01:00
parent 9f97ab1d60
commit 002f4aeadd

View File

@@ -117,21 +117,17 @@ const UserWebPushSettings = () => {
localStorage.setItem('pushNotificationsEnabled', 'false');
setWebPushEnabled(false);
// Only delete the current browser's subscription, not all devices
const endpointToDelete = unsubscribedEndpoint || subEndpoint || endpoint;
const endpointsToDelete: string[] = endpointToDelete
? [endpointToDelete]
: dataDevices?.map((device: { endpoint: string }) => device.endpoint) ??
[];
for (const ep of endpointsToDelete) {
if (endpointToDelete) {
try {
await axios.delete(
`/api/v1/user/${user?.id}/pushSubscription/${encodeURIComponent(
ep
endpointToDelete
)}`
);
} catch {
// Ignore individual deletion failures - backend cleanup is best effort
// Ignore deletion failures - backend cleanup is best effort
}
}
@@ -174,19 +170,17 @@ const UserWebPushSettings = () => {
useEffect(() => {
const verifyWebPush = async () => {
const enabled = await verifyPushSubscription(user?.id, currentSettings);
const hasBackendSubscriptions = dataDevices && dataDevices.length > 0;
const isEnabled = enabled || hasBackendSubscriptions;
setWebPushEnabled(isEnabled);
setWebPushEnabled(enabled);
localStorage.setItem(
'pushNotificationsEnabled',
isEnabled ? 'true' : 'false'
enabled ? 'true' : 'false'
);
};
if (user?.id) {
verifyWebPush();
}
}, [user?.id, currentSettings, dataDevices]);
}, [user?.id, currentSettings]);
useEffect(() => {
const getSubscriptionEndpoint = async () => {