FCM testing

This commit is contained in:
2026-03-23 09:32:25 -04:00
parent 14c80f436a
commit edc7885a6b

View File

@@ -112,7 +112,7 @@ export default function Chat() {
// Dynamically import the Firebase SDK (tree-shaken, only loaded when needed)
const { initializeApp, getApps } = await import('firebase/app');
const { getMessaging, getToken } = await import('firebase/messaging');
const { getMessaging, getToken, deleteToken } = await import('firebase/messaging');
const firebaseApp = getApps().length
? getApps()[0]
@@ -126,6 +126,13 @@ export default function Chat() {
if (granted !== 'granted') return;
}
// Always delete any cached token first so we get a fresh Web Push subscription.
// Stale tokens (e.g. from a previous install or a Chrome push-subscription reset)
// still look valid to Firebase but silently fail to deliver — deleteToken forces
// Chrome to create a brand-new subscription and register it with FCM.
console.log('[Push] Clearing any cached FCM token...');
await deleteToken(firebaseMessaging).catch(() => {});
console.log('[Push] Requesting FCM token...');
const fcmToken = await getToken(firebaseMessaging, {
vapidKey,