fix: delete endpoint on push notification disable (#2067)

fix: add endpoint deletion on disable

fix: use definemessages util

refactor: add code comment
This commit is contained in:
Brandon Cohen
2025-10-18 12:03:28 -04:00
committed by GitHub
parent 0d6bfa18cc
commit a975ab25c3
2 changed files with 13 additions and 4 deletions

View File

@@ -269,16 +269,20 @@ router.delete<{ userId: number; endpoint: string }>(
try {
const userPushSubRepository = getRepository(UserPushSubscription);
const userPushSub = await userPushSubRepository.findOneOrFail({
relations: {
user: true,
},
const userPushSub = await userPushSubRepository.findOne({
relations: { user: true },
where: {
user: { id: req.params.userId },
endpoint: req.params.endpoint,
},
});
// If not found, just return 204 to prevent push disable failure
// (rare scenario where user push sub does not exist)
if (!userPushSub) {
return res.status(204).send();
}
await userPushSubRepository.remove(userPushSub);
return res.status(204).send();
} catch (e) {

View File

@@ -111,6 +111,11 @@ const UserWebPushSettings = () => {
try {
await unsubscribeToPushNotifications(user?.id, endpoint);
// Delete from backend if endpoint is available
if (subEndpoint) {
await deletePushSubscriptionFromBackend(subEndpoint);
}
localStorage.setItem('pushNotificationsEnabled', 'false');
setWebPushEnabled(false);
addToast(intl.formatMessage(messages.webpushhasbeendisabled), {