firebase remove not valid token

Solutions on MaxInterview for firebase remove not valid token by the best coders in the world

showing results for - "firebase remove not valid token"
Sebastián
24 Jul 2016
1admin.messaging().sendToDevice(tokens, payload).then((response) => {
2  // For each message check if there was an error.
3  const tokensToRemove = [];
4  response.results.forEach((result, index) => {
5    const error = result.error;
6    if (error) {
7      console.error('Failure sending notification to', tokens[index], error);
8      // Cleanup the tokens who are not registered anymore.
9      if (error.code === 'messaging/invalid-registration-token' ||
10          error.code === 'messaging/registration-token-not-registered') {
11        // TODO: remove the token from your registry/database
12      }
13    }
14  });
15});
16