Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Invalid push notification tokens are not cleaned up from database for FCM API v2 #9173

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
) {
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);

Check warning on line 253 in src/StatusHandler.js

View check run for this annotation

Codecov / codecov/patch

src/StatusHandler.js#L253

Added line #L253 was not covered by tests
}
// APNS errors; see:
// https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns
if (error === 'Unregistered' || error === 'BadDeviceToken') {
devicesToRemove.push(token);
}
Expand Down
Loading