FCM: Sending notifications to old tokens on web platform
@chong-shao đang làm issue này rồi.
Từ ngày 24/2/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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?
- Ngôn ngữ chính
- TypeScript
- Star
- 1.7k
- Fork
- 419
- Merge trung bình
- 4 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 16
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của firebase/firebase-admin-node
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
firebase/firebase-admin-node#3234 ·
-
firebase/firebase-admin-node#3221 · 3 bình luận · 1 người được giao ·
-
api: messaging
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 70/100
firebase/firebase-admin-node#3215 ·
-
api: messaging
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
firebase/firebase-admin-node#3214 ·
-
api: firestore type: feature request
firebase/firebase-admin-node#3183 · 1 bình luận · 1 người được giao ·
Tất cả issue của firebase/firebase-admin-node
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
mksglu/context-mode#1200 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/claude-code#96687 ·
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
AOSSIE-Org/DebateAI#582 · 2 bình luận ·