How to verify FCM registration token on server?

后端 未结 4 1666
独厮守ぢ
独厮守ぢ 2020-11-29 09:43

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

4条回答
  •  星月不相逢
    2020-11-29 10:15

    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
    })
    

提交回复
热议问题