3

I've been pulling out my hair trying to set Appsync and Cognito in my React Native app.

I've tried the two following ways:

Amplify.configure(config);

OR

Amplify.configure({
  Auth: {
    region: config.aws_cognito_region, // REQUIRED - Amazon Cognito Region
    userPoolId: config.aws_user_pools_id, // OPTIONAL - Amazon Cognito User Pool ID
    userPoolWebClientId: config.aws_user_pools_web_client_id, // User Pool App Client ID
  },
});

AND

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authType,
    jwtToken: async () => (await Auth.currentSession()).getIdToken().getJwtToken(),
  },
});

OR

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authType,
    apiKey: appSyncConfig.apiKey,
  },
});

I've also followed these two tutorials Tackling user auth, Building a notes app.

In both cases, I get the following error in GraphQL with no description:

Error: Network error: Response not successful: Received status code

This is while in Authorization Type is Amazon Cognito User Pool. I've also tried AWS Identity and Access Management (IAM), but that gives me a 403 error. Can someone point me in a direction where I can debug this further?

Aryan Goharzad
  • 177
  • 1
  • 11

2 Answers2

1

It might be caused a typo in the docs / article you've read. Trying replacing :

auth: {
type: appSyncConfig.authType,
apiKey: appSyncConfig.apiKey
}

with :

auth: {
type: appSyncConfig.authenticationType,
apiKey: appSyncConfig.apiKey
}
0

I have the following code and its working for me:

import Amplify, { Auth } from 'aws-amplify';
import API, { graphqlOperation } from '@aws-amplify/api'

window.LOG_LEVEL = 'DEBUG';
Amplify.configure({
  Auth: {
    "identityPoolId":'ap-southeast-1:xxxxxx',
    "mandatorySignIn": false,
    "region": "ap-southeast-1",
    "userPoolId": "ap-southeast-1_xxxx",
    "userPoolWebClientId": "xxxxxxx"
  },
  API:{
    "aws_appsync_graphqlEndpoint": 'https://xxxx.ap-southeast-1.amazonaws.com/graphql',
    "aws_appsync_region": 'ap-southwest-1',
    "aws_appsync_authenticationType": 'AMAZON_COGNITO_USER_POOLS',
    "aws_appsync_apiKey": 'null',
  }

});
Biranchi
  • 16,120
  • 23
  • 124
  • 161