Skip to content

Commit

Permalink
fix: Invalid push notification tokens are not cleaned up from databas…
Browse files Browse the repository at this point in the history
…e for FCM API v2 (#9173)
  • Loading branch information
mtrezza committed Jul 1, 2024
1 parent 91dde99 commit 284da09
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/StatusHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,23 @@ export function pushStatusHandler(config, existingObjectId) {
) {
const token = result.device.deviceToken;
const error = result.response.error;
// GCM errors
// GCM / FCM HTTP v1 API errors; see:
// https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
if (error === 'NotRegistered' || error === 'InvalidRegistration') {
devicesToRemove.push(token);
}
// APNS errors
// FCM API v2 errors; see:
// https://firebase.google.com/docs/cloud-messaging/manage-tokens
// https://github.com/firebase/functions-samples/blob/703c0359eacf07a551751d1319d34f912a2cd828/Node/fcm-notifications/functions/index.js#L89-L93C16
if (
error?.code === 'messaging/registration-token-not-registered' ||
error?.code === 'messaging/invalid-registration-token' ||
(error?.code === 'messaging/invalid-argument' && error?.message === 'The registration token is not a valid FCM registration token')
) {
devicesToRemove.push(token);
}
// APNS errors; see:
// https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns
if (error === 'Unregistered' || error === 'BadDeviceToken') {
devicesToRemove.push(token);
}
Expand Down

0 comments on commit 284da09

Please sign in to comment.