Skip to content

Commit a975ab2

Browse files
authored
fix: delete endpoint on push notification disable (#2067)
fix: add endpoint deletion on disable fix: use definemessages util refactor: add code comment
1 parent 0d6bfa1 commit a975ab2

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

  • server/routes/user
  • src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush

server/routes/user/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,20 @@ router.delete<{ userId: number; endpoint: string }>(
269269
try {
270270
const userPushSubRepository = getRepository(UserPushSubscription);
271271

272-
const userPushSub = await userPushSubRepository.findOneOrFail({
273-
relations: {
274-
user: true,
275-
},
272+
const userPushSub = await userPushSubRepository.findOne({
273+
relations: { user: true },
276274
where: {
277275
user: { id: req.params.userId },
278276
endpoint: req.params.endpoint,
279277
},
280278
});
281279

280+
// If not found, just return 204 to prevent push disable failure
281+
// (rare scenario where user push sub does not exist)
282+
if (!userPushSub) {
283+
return res.status(204).send();
284+
}
285+
282286
await userPushSubRepository.remove(userPushSub);
283287
return res.status(204).send();
284288
} catch (e) {

src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ const UserWebPushSettings = () => {
111111
try {
112112
await unsubscribeToPushNotifications(user?.id, endpoint);
113113

114+
// Delete from backend if endpoint is available
115+
if (subEndpoint) {
116+
await deletePushSubscriptionFromBackend(subEndpoint);
117+
}
118+
114119
localStorage.setItem('pushNotificationsEnabled', 'false');
115120
setWebPushEnabled(false);
116121
addToast(intl.formatMessage(messages.webpushhasbeendisabled), {

0 commit comments

Comments
 (0)