Open adelpro opened 2 years ago
is it going to work well with latest firebase version "firebase": "^10.6.0",
in my project its not working
this error is coming and also this react is created with vite in ts .
Catch og getToken FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope
suggested solution: get the token with asynch with ".then()" code: const vapidKey = "BDEASiE-8W4AwXjKPVUGqPf93FCAFophD8F2l1-cfJRgJyQjCaprz0NVVUnzSrM9QRYuKgrX_dTt6jBcfktR-U8"; export const requestForToken = () => { getToken(messaging, { vapidKey }).then((currentToken) => { if (currentToken) { //do anything with token console.log("current token for client: ", currentToken); } else { // Show permission request UI console.log( "No registration token available. Request permission to generate one." ); } }); };
@adelpro it is due to react strictmode 2 times rendering
suggested solution: get the token with asynch with ".then()" code: const vapidKey = "BDEASiE-8W4AwXjKPVUGqPf93FCAFophD8F2l1-cfJRgJyQjCaprz0NVVUnzSrM9QRYuKgrX_dTt6jBcfktR-U8"; export const requestForToken = () => { getToken(messaging, { vapidKey }).then((currentToken) => { if (currentToken) { //do anything with token console.log("current token for client: ", currentToken); } else { // Show permission request UI console.log( "No registration token available. Request permission to generate one." ); } }); };