Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

FCM: Sending notifications to old tokens on web platform

未关闭
#2,822 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@chong-shao 已经在做这个了。

开始于 2025年2月24日。

评估

这个 Issue 还没有评估数据。

描述

api: messaging

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:
  1. Run the web application and retrieve the notification token.
  2. Call the sendNotification function using the token, and everything works as expected—the notification is successfully sent to the browser.
  3. Close my Flutter app and reopen it, generating a new token.
  4. 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/firebase-admin-node 的其他 Issue

查看 firebase/firebase-admin-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。