Firebase key error

0

I'm doing a PWA using Vue and Quasar, but when I make a request in Postman to appear a push notification I get the following return in Postman:

{
    "multicast_id": idMulticast, //removido por mim ao postar aqui
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "NotRegistered"
        }
    ]
}

I have already researched a lot about this error and the closest I got to the solution was the question of link , but I have generated the keys again dozens of times and had no way of working, always returning the same error in Postman.

I'm following all the steps correctly, and here is the source code I have as a basis for my PWA.

    
asked by anonymous 29.03.2018 / 22:34

1 answer

0

Your error is documented here :

  

A current registry token may no longer be valid in several   situations, such as:

     
  • If the client app canceled the registration with FCM.
  •   
  • If the client app has the registry automatically canceled, something that can occur if the user uninstalls the app. For example, on iOS,   if the APN feedback service reported their token as invalid.
  •   
  • If the registration token expires, for example, if Google updates the registration tokens, or the APN token has expired for devices   iOS.
  •   
  • If the client app is up to date, but the new version is not configured to receive messages.
  •   

For all these cases, remove the app token from the app server   and stop using it to send messages.

As the last paragraph says, the best thing to do is to update the token. I see that in your case this token is obtained in the push.js file from the repository What did you link to in your question? However, it is only obtained once, which means that if it expires it will not be updated. (And, of course, FCM can not receive messages from an expired token.)

To update this token, use the onTokenRefresh () :

messaging.onTokenRefresh(function() {
  messaging.getToken().then(function(novoToken) {
    console.log('O token mudou.');
    console.log('Enviar isso para um servidor:', novoToken);

  }).catch(function(err) {
    console.log('Não foi possível obter o novo token ', err);
  });
});
    
30.03.2018 / 17:56