mallix
mallix

Reputation: 1429

Firebase js client - sendTokenToServer is not defined

I am trying to test a server implementation for pushing messages to clients.

For that reason I integrated Firebase push notifications JS SDK in my local environment to preview those messages in my browser.

Followed the official documentation: https://firebase.google.com/docs/cloud-messaging/js/client

I am able to retrieve the token (visible in my browser's console) but I get the error below:

An error occurred while retrieving token.  ReferenceError: sendTokenToServer is not defined

Which comes out of the block below while the client is trying to register itself to FCM:

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

Tried on both Chrome and Firefox with the same results.

What am I missing?

Upvotes: 0

Views: 1392

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317412

I think you are misunderstanding the documentation. sendTokenToServer is not a provided function for you to use. You're supposed to provide the implementation of that. Its responsibility is to send the token to your own server or backend so it can be used by your backend code that will send messages to the devices represented by those tokens.

Upvotes: 3

Related Questions