From 2888f843e3c97ae731c6f08ada96dd86bb2181b5 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Tue, 28 Apr 2020 16:16:10 +0200 Subject: [PATCH] fix(push notifications): remove tokens after a MismatchSenderId error --- website/server/libs/pushNotifications.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/website/server/libs/pushNotifications.js b/website/server/libs/pushNotifications.js index ebbad83b4a..da2284c2f3 100644 --- a/website/server/libs/pushNotifications.js +++ b/website/server/libs/pushNotifications.js @@ -92,7 +92,13 @@ export function sendNotification (user, details = {}) { // from when failed === NotRegistered // Blacklisted can happen in some rare cases, // see https://stackoverflow.com/questions/42136122/why-does-firebase-push-token-return-blacklisted - if (failed === 'InvalidRegistration' || pushDevice.regId === 'BLACKLISTED') { + // MismatchSenderId could be due to old tokens, + // see https://stackoverflow.com/questions/11313342/why-do-i-get-mismatchsenderid-from-gcm-server-side + if ( + failed === 'InvalidRegistration' + || failed === 'MismatchSenderId' + || pushDevice.regId === 'BLACKLISTED' + ) { removePushDevice(user, pushDevice); } logger.error(new Error('FCM error'), {