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?
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?
Share Improve this question edited Dec 5, 2019 at 8:54 Peter Haddad 81k25 gold badges145 silver badges146 bronze badges asked Apr 18, 2018 at 6:12 Bargain23Bargain23 1,9734 gold badges32 silver badges58 bronze badges1 Answer
Reset to default 8In the docs it says:
// This registration token es 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