我一直在努力尝试在我的React Native应用程序中设置Appsync和Cognito。
我尝试了以下两种方法:
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,
},
});
我还遵循了Tackling user auth,Building a notes app这两个教程。
在两种情况下,我在GraphQL中都收到以下错误,但没有描述:
Error: Network error: Response not successful: Received status code
这是在“授权类型”为Amazon Cognito User Pool
时。我也尝试过AWS Identity and Access Management (IAM)
,但这给了我403错误。有人可以指出我可以进一步调试的方向吗?
答案 0 :(得分:1)
这可能是您所阅读的文档/文章中的错字。尝试更换:
auth: {
type: appSyncConfig.authType,
apiKey: appSyncConfig.apiKey
}
与:
auth: {
type: appSyncConfig.authenticationType,
apiKey: appSyncConfig.apiKey
}
答案 1 :(得分:0)
我有以下代码及其适用的代码:
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',
}
});