File tree Expand file tree Collapse file tree
src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 ) , {
You can’t perform that action at this time.
0 commit comments