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.

gefragt vor 2 Jahren90 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen