简体   繁体   中英

#AskFirebase FCM web push token invalidation time

Do FCM tokens generated using Firebase JS SDK ever expire when user is offline too long?
For example, after calling the following code:

messaging.getToken().then((currentToken) => {
  if (currentToken) {
    sendTokenToServer(currentToken);
    updateUIForPushEnabled(currentToken);
  } else {
    // Show permission request.
    console.log('No Instance ID token available. Request permission to generate one.');
    // Show permission UI.
    updateUIForPushPermissionRequired();
    setTokenSentToServer(false);
  }
}).catch((err) => {
  console.log('An error occurred while retrieving token. ', err);
  showToken('Error retrieving Instance ID token. ', err);
  setTokenSentToServer(false);
});

The server has the client token. If the user clears the site data, the client no longer knows of this registration, and no one updates the server that the client is gone. So does it ever invalidates the token? If so, how long does it take to invalidate? I understand that FCM can save messages up to 28 days, so I'm assuming no less than that amount of time?

Tokens might be invalidated for a number of reasons. According to the documentation :

The registration token may change when:

  • The web app deletes the registration token.
  • The user clears browser data. In this case, call getToken to retrieve the new token.

The documentation doesn't say anything about expiration times, but your code should be prepared to handle these cases by detecting the change and sending the new token to your backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM