Bargain23
Bargain23

Reputation: 1973

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?

Upvotes: 8

Views: 9439

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80944

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

Upvotes: 8

Related Questions