Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Admin - where are the registration tokens for web app users?

I'm following the example on the documentations, but I'm confused about registration tokens. I'm testing the push notifications on my local express server. How exactly do I retrieve the current registration token, and how do I generate registration tokens for multiple web app users?

like image 585
Bargain23 Avatar asked Apr 18 '18 06:04

Bargain23


1 Answers

In the docs it says:

// This registration token comes from the client FCM SDKs.
var registrationToken = 'YOUR_REGISTRATION_TOKEN';`

To get the user's token:

 messaging.getToken().then(function(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(function(err) {
console.log('An error occurred while retrieving token. ', err);
showToken('Error retrieving Instance ID token. ', err);
setTokenSentToServer(false);
  });
}

more info here

Then add the token to the database and retrieve it in the Admin SDK

more info here: Retrieve data in Admin SDK

like image 77
Peter Haddad Avatar answered Sep 21 '22 18:09

Peter Haddad