firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

firebase.messaging().deleteToken(Token) Failed on Firebase WEB SDK 7.6.1 #3325

Closed fhajarf closed 4 years ago

fhajarf commented 4 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

error

Steps to reproduce:

The issue occurs when a use grants notification permissions, gets a FCM token, then updates the notification permissions in the browser back to Ask (default), reloads the page, grants notification permissions again in Chrome, and get an error when trying to getToken at this point. Note: subsequent calls to getToken don't face this issue.

Relevant Code:

if(messaging){ messaging.requestPermission() .then(async () => { const token = await messaging.getToken(); const user= JSON.parse(localStorage.getItem('userObj')); var isMyObjectEmpty = !Object.keys(user).length; const doc = await db.collection('tokens').doc('webTokens').get(); if(user && !isMyObjectEmpty){ db.collection('tokens').doc(user.uid).set({webPushToken: token}, {merge: true}).then(() => { }).catch((error) => { console.log(error.message,'here we are'); }) } if(doc.exists){ db.collection('tokens').doc('webTokens').update({tokens: firebase.firestore.FieldValue.arrayUnion(token)}).then(() => { }).catch((error) => { console.log(error.message,'hahaha'); }) } else { console.log("Doc dosen't exist "); } }) .catch((err) => { console.log("Unable to get permission to notify.", err.code); }); navigator.serviceWorker.addEventListener("message", (message) => console.log(message));

google-oss-bot commented 4 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

zwu52 commented 4 years ago

Hi fhajarf, thanks for reporting. It looks like this might be a duplicate of #2364. If there is no objection, I'll close this issue and update on that. Cheers.