Error of Keys Firebase

Asked

Viewed 57 times

0

I’m doing a PWA using Vue and Quasar, but when I make a request in Postman to appear a push notification I have 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 mistake and the closest I came to the solution was the question of this link, but I have managed the Keys again dozens of times and had no way to work, 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.

1 answer

0


Your mistake is documented here:

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

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

For all these cases, remove the registration 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 file push js. from the repository you linked to in your question. However, it is only obtained once, which means that if it expires it will not be updated. (And obviously the FCM cannot receive messages from an expired token)

To update this token, use the function 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);
  });
});
  • I tried using this function above but it is still not working, could give me an example of where to put it to work properly, because it is still returning the same error...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.