Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

FCM: Sending notifications to old tokens on web platform

Abierto
#2,822 1 comentario 0 reacciones 1 asignado Ver en GitHub

@chong-shao ya está trabajando en esto.

Desde el 24/2/2025.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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?

Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
4 d 20 h
PR fusionados (30 d)
16

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de firebase/firebase-admin-node

Todos los issues de firebase/firebase-admin-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.