fix(webpush): only remove the current browser's subscription
Signed-off-by: 0xsysr3ll <0xsysr3ll@pm.me>
This commit is contained in:
@@ -117,21 +117,17 @@ const UserWebPushSettings = () => {
|
|||||||
localStorage.setItem('pushNotificationsEnabled', 'false');
|
localStorage.setItem('pushNotificationsEnabled', 'false');
|
||||||
setWebPushEnabled(false);
|
setWebPushEnabled(false);
|
||||||
|
|
||||||
|
// Only delete the current browser's subscription, not all devices
|
||||||
const endpointToDelete = unsubscribedEndpoint || subEndpoint || endpoint;
|
const endpointToDelete = unsubscribedEndpoint || subEndpoint || endpoint;
|
||||||
const endpointsToDelete: string[] = endpointToDelete
|
if (endpointToDelete) {
|
||||||
? [endpointToDelete]
|
|
||||||
: dataDevices?.map((device: { endpoint: string }) => device.endpoint) ??
|
|
||||||
[];
|
|
||||||
|
|
||||||
for (const ep of endpointsToDelete) {
|
|
||||||
try {
|
try {
|
||||||
await axios.delete(
|
await axios.delete(
|
||||||
`/api/v1/user/${user?.id}/pushSubscription/${encodeURIComponent(
|
`/api/v1/user/${user?.id}/pushSubscription/${encodeURIComponent(
|
||||||
ep
|
endpointToDelete
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
} catch {
|
} 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(() => {
|
useEffect(() => {
|
||||||
const verifyWebPush = async () => {
|
const verifyWebPush = async () => {
|
||||||
const enabled = await verifyPushSubscription(user?.id, currentSettings);
|
const enabled = await verifyPushSubscription(user?.id, currentSettings);
|
||||||
const hasBackendSubscriptions = dataDevices && dataDevices.length > 0;
|
setWebPushEnabled(enabled);
|
||||||
const isEnabled = enabled || hasBackendSubscriptions;
|
|
||||||
setWebPushEnabled(isEnabled);
|
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'pushNotificationsEnabled',
|
'pushNotificationsEnabled',
|
||||||
isEnabled ? 'true' : 'false'
|
enabled ? 'true' : 'false'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (user?.id) {
|
if (user?.id) {
|
||||||
verifyWebPush();
|
verifyWebPush();
|
||||||
}
|
}
|
||||||
}, [user?.id, currentSettings, dataDevices]);
|
}, [user?.id, currentSettings]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getSubscriptionEndpoint = async () => {
|
const getSubscriptionEndpoint = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user