I got my Firebase Cloud Messaging registration token for web push. And I sent this to my server to save in database for later push. But how can I verify this token is valid
If anyone using firebase Admin SDK for node.js, there is no need to manually send the request using the server_key explicitly. Admin SDK provide sending dry_run push message to verify the fcm_token.
function verifyFCMToken (fcmToken) => {
return admin.messaging().send({
token: fcmToken
}, true)
}
Use this method like following
verifyFCMToken("YOUR_FCM_TOKEN_HERE")
.then(result => {
// YOUR TOKEN IS VALID
})
.catch(err => {
// YOUR TOKEN IS INVALID
})