File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,26 @@ router.post<
225225 return res . status ( 204 ) . send ( ) ;
226226 }
227227
228+ // Clean up old subscriptions from the same device (userAgent) for this user
229+ // iOS can silently refresh endpoints, leaving stale subscriptions in the database
230+ if ( req . body . userAgent ) {
231+ const staleSubscriptions = await userPushSubRepository . find ( {
232+ relations : { user : true } ,
233+ where : {
234+ userAgent : req . body . userAgent ,
235+ user : { id : req . user ?. id } ,
236+ } ,
237+ } ) ;
238+
239+ if ( staleSubscriptions . length > 0 ) {
240+ await userPushSubRepository . remove ( staleSubscriptions ) ;
241+ logger . debug (
242+ `Removed ${ staleSubscriptions . length } stale push subscription(s) from same device.` ,
243+ { label : 'API' }
244+ ) ;
245+ }
246+ }
247+
228248 const userPushSubscription = new UserPushSubscription ( {
229249 auth : req . body . auth ,
230250 endpoint : req . body . endpoint ,
You can’t perform that action at this time.
0 commit comments