amplify-js: UpdateEndpoint does not create Push Notification subscription

Describe the bug Running updateEndpoint from a React web application doesn’t actually create the endpoint in Pinpoint with the device token associated with it. It will not associate the Cognito user either.

To Reproduce The following code snippet, when run in a React web application (not React Native) succeeds, but does not send the channelType, address or userId to Amazon Pinpoint.

import { Analytics } from 'aws-amplify';

await Analytics.updateEndpoint({
    address: deviceToken,
    channelType: 'GCM',
    userId: this.props.user.username, // i.e. ferdingler
    userAttributes: {
        ...this.props.user // i.e. attributes like email and full name
    }
});

Expected behavior The previous code should update or create an endpoint in Amazon Pinpoint with the device token specified and linked to the userId provided. The following code snippet works correctly (this is not using Amplify):

const pinpoint = new AWS.Pinpoint({
    region: 'us-west-2',
    credentials: Auth.essentialCredentials(credentials),
});

const response = await pinpoint.updateEndpoint({
    ApplicationId: '4289.......f0d',
    EndpointId: uuid(),
    EndpointRequest: {
        Address: deviceToken,
        ChannelType: 'GCM',
        User: {
            UserId: this.props.user.username,
        },
    },
}).promise();

Desktop (please complete the following information):

  • OS: macOS High Sierra
  • Browser Chrome
  • Version v71.x

Additional context The use case is about sending Web Push Notifications with Amazon Pinpoint -> Firebase Cloud Messaging and receiving them in a React web app using Amplify.

Taking a quick glance at the Amplify internal code, it seems that this is by design and not actually a bug. But it does feel like one. The documentation doesn’t warn that this cannot be run from a web app, and the fact that the call succeeds but ignores the data provided is misleading.

Any guidance will be very much appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 25 (4 by maintainers)

Most upvoted comments

@dylan-westbury What I have right now is I added PushNotification.onRegister(token => { ... }) right after PushNotification.configure. Within onRegister I call Analytics.updateEndpoint and assign the address to the token with an explicit optOut: NONE.

It works, but I don’t love this method, because it makes several calls to updateEndpoint (you have it in Analytics.configure, PushNotification.configure, and now here). But I guess if you wanted something quick and dirty this would work. I have seen some posts about AsyncStorage not working as expected, and am thinking that may be part of the problem. I’m going to do some more research and see if that really is the problem and if there is a workaround. I’ll try to get back if I figure it out!

Let me know if you find anything as well 👍