Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
Firebase getToken no funciona después de cambiar Service Worker

Para las notificaciones de inserción de Firebase 9.5.0, tenemos un trabajador de servicio que recibe la inserción de Firebase, todos los trabajadores de servicio funcionan bien.

Sin embargo, estamos migrando de un registro de trabajador de servicio antiguo (de un tercero) a nuestro propio registro, todos los usuarios nuevos funcionan bien al registrarse y obtener un token, pero recibimos un error cuando queremos usar un nuevo trabajador de servicio para un usuario registrado existente (con un antiguo service-worker de un tercero).

El error ocurre en getToken que causa el error

 FirebaseError: Messaging: A problem occurred while subscribing the user to FCM: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.

Espero que podamos agregar algún código en la catch para hacer algo como volver a registrar al usuario o algo así, pero mirando los documentos de Firebase, no puedo encontrar nada sobre cómo registraríamos al usuario con nosotros mismos sin un error.

 import { initializeApp } from "https://www.gstatic.com/firebasejs/9.5.0/firebase-app.js"; import { deleteToken, getMessaging, getToken, isSupported, onMessage } from "https://www.gstatic.com/firebasejs/9.5.0/firebase-messaging.js"; const firebaseConfig = { apiKey: ... authDomain: ... projectId: ... storageBucket: ... messageSenderId: ... appId: ... measurementId: ... }; const firebaseApp = initializeApp(firebaseConfig); const messaging = getMessaging(firebaseApp); const registerServiceWorker = () => { if ('serviceWorker' in navigator) { navigator.serviceWorker.register('serviceworkerfilename.js') .then( function( registration) { console.log('reg successful', registration); // gets here ok getToken( messaging, { serviceWorkerRegistration: registration } ) .then(function(currentToken) { // do stuff, this normally works for a new user, but not on old service worker }) .catch( function(err) { // always gets here for old user from old service worker Notification.requestPermission().then(function(permission) { console.log(permission); // gets here, and shows 'granted', but stuck from here what we can do to reset the user }); }); }) } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Así que resolví esto primero con un cheque para verificar con el nombre de archivo que tenía el trabajador del servicio

 navigator.serviceWorker.controller.scriptURL.match(<someregex>)

Y luego, si lo desea, elimine el registro del trabajador de servicio existente...

 navigator.serviceWorker.getRegistrations() .then( function(registrations) { for(let registration of registrations) { registration.unregister(); } });

Y luego, si es necesario, llame a una función para registrarse nuevamente.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!