FCM: Sending notifications to old tokens on web platform
@chong-shao is already working on this.
Since Feb 24, 2025.
Assessment
This issue has not been assessed yet.
Description
I’m using Flutter in my client app to handle notifications. I retrieve the token from the device, and for testing purposes, I’ve created a Firebase Cloud Function that accepts the token and sends a test notification to the browser. The function is as follows:
exports.sendNotification = functions.https.onRequest(async (_, response) => {
const message = {
notification: {
title: 'Title',
body: 'Body',
},
token: 'token',
};
try {
await admin.messaging().send(message);
response.status(200).send('Notification sent successfully');
} catch (error) {
console.error('Error sending notification:', error);
// Delete token for user if error code is UNREGISTERED or INVALID_ARGUMENT.
if (error.code == "messaging/registration-token-not-registered") {
// If you're running your own server, call API to delete the
// token for the user
console.log('Token is no longer valid: ', message.token);
}
response.status(500).send('Error sending notification: ' + error);
}
});
This function is running in the Firebase emulator.
Workflow:
- Run the web application and retrieve the notification token.
- Call the sendNotification function using the token, and everything works as expected—the notification is successfully sent to the browser.
- Close my Flutter app and reopen it, generating a new token.
- Attempt to send a notification using the old token.
Observed Behavior:
- On the web, the notifications are still sent successfully with the old token, even after the app is reopened and the token changes.
- On Android, using an old token correctly triggers the messaging/registration-token-not-registered error code, and the function logs that the token is no longer valid.
Shouldn't the behavior be consistent across web and Android? Is there a specific reason why notifications are still being sent to old tokens on the web platform?
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 419
- Avg merge
- 4d 20h
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebase-admin-node
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
firebase/firebase-admin-node#3234 ·
-
firebase/firebase-admin-node#3221 · 3 comments · 1 assignee ·
-
api: messaging
Difficulty 3/5 1-2 days Newbie friendliness 70/100
firebase/firebase-admin-node#3215 ·
-
api: messaging
Difficulty 5/5 Over a week Newbie friendliness 28/100
firebase/firebase-admin-node#3214 ·
-
api: firestore type: feature request
firebase/firebase-admin-node#3183 · 1 comment · 1 assignee ·
All issues in firebase/firebase-admin-node
Similar issues
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Mend: dependency security vulnerability untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 70/100