Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda