Amplify API subscription failing authorization

0

I have a React application that currently uses Amplify GraphQL APIs. I have set those APIs up so that they require using Cognito user pools for authorization. For example the following code is successfully retrieving a list of values from my Projects collection in DynamoDB

const apiData = await API.graphql({ query: listProjects, authMode: "AMAZON_COGNITO_USER_POOLS"  });

Recently I have been trying to setup a subscription so that I can receive real time updates from AppSync when new entries are added to my Projects collection. This is the code that I am trying to get to work:

const subscription = API.graphql({query: subscriptions.onUpdateProject, authMode: "AMAZON_COGNITO_USER_POOLS"}
    ).subscribe({
    next: ({ provider, value }) => console.log({ provider, value }),
    error: error => console.warn(error)
});

Unfortunately, this code is failing when executed, it is causing this error to be raised:

"Connection failed: {\"errors\":[{\"errorType\":\"Unauthorized\",\"message\":\"Not Authorized to access onUpdateProject on type Project\"}]}"

I am not quite sure how to troubleshoot this or resolve it, do subscriptions require a special configuration with respect to authorization? Are Cognito user pools supported with subscriptions? Any help or guidance would be greatly appreciated.

已提问 2 年前90 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则