FCM: Sending notifications to old tokens on web platform
@chong-shao 已经在做这个了。
开始于 2025年2月24日。
评估
这个 Issue 还没有评估数据。
描述
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?
- 主要语言
- TypeScript
- 星标
- 1.7k
- 派生
- 419
- 平均合并
- 4 天 20 小时
- 30 天内合并 PR
- 16
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-admin-node 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
firebase/firebase-admin-node#3234 ·
-
firebase/firebase-admin-node#3221 · 3 条评论 · 已指派 1 人 ·
-
api: messaging
难度 3/5 1-2 天 新手友好度 70/100
firebase/firebase-admin-node#3215 ·
-
api: messaging
难度 5/5 一周以上 新手友好度 28/100
firebase/firebase-admin-node#3214 ·
-
api: firestore type: feature request
firebase/firebase-admin-node#3183 · 1 条评论 · 已指派 1 人 ·
查看 firebase/firebase-admin-node 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 1/5 1 小时以内 新手友好度 90/100
TanStack/tanstack.com#1293 ·