Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
How to make React only allow user to the next page if accepted FCM notification request?

I want my site to only allow the user to the next page if they accepted the notification request and their token are already uploaded to Firestore. I can't seem to figure out how to do it properly.

This is my code for asking for permission and uploading the token:

    const messaging = firebase.messaging();
    
    
    function InitializeFirebaseMessaging(){
      messaging.requestPermission().then(function(){
        
        console.log("Notification permission");
        return messaging.getToken();
      }).then(function(token){
        console.log("Token: "+token);
       
        firestore.collection("tokens").doc(auth.currentUser.email).set({
          mail: auth.currentUser.email,
          token: token 
      }).then(function(){
    perm=true;
  });
      
      }).catch(function (reason){
        console.log(reason);
      });
    }
    messaging.onMessage(function (payload){
      
      console.log(payload);
    });
    messaging.onTokenRefresh(function () {
      messaging.getToken()
          .then(function (newtoken) {
            
              console.log("New Token : "+ newtoken);
             
          })
          .catch(function (reason) {
              console.log(reason);
          })
     });

This is a piece of code I use to check if there is a token saved AND the current browser/pwa app accepted the notifications.

function ChatRoom(){
....
InitializeFirebaseMessaging();
.......
   firestore.collection("tokens").doc(auth.currentUser.email).get().then((da)=> {
          console.log("tokentest: " + da.data().token);
          if (da.data().token!=null&&perm){
            console.log("here??");
            setSelfToken(true);
          }
        });
}

When I try to log in, it does not step to the next page even if I accepted the notifications. The token does not get uploaded to Firestore, and I keep getting this error:

DOMException: Registration failed - push service error

Any idea how could I fix it? Users must accept the notifications, and their saved tokens must be saved/updated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda