带有选项未定义错误的AWS放大api.get federateInfo [英] aws-amplify api.get federateInfo with options undefined error
问题描述
我在玩aws-amplify和react-native.我正在尝试在主屏幕上进行api.get调用,但一直遇到错误:
获取项目:键为federatedInfo,其选项未定义
我正在调用aws-api-gateway dynamodb.我一直在寻找与文档的修复程序,但大多数指向使用HOC withAuthenticator.我不想这样做,因为我已经自定义了内置的SignIn/signUP/Confirm屏幕.任何帮助或仅在正确方向上的指导都将是非常有用的.这是我的Home.screen代码:
I am playing around with aws-amplify and react-native. I am trying to make an api.get call on my home screen but keep running into the error:
Get item: key is federatedInfo with options undefined
I am calling an aws-api-gateway dynamodb. I have been looking at fixes with docs but most point to using HOC withAuthenticator. I don't want to do this since i've custom built signIn/signUP/Confirm screens. Any help or just a point in the right direction would be great. Here is my Home.screen code:
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Button } from "react-native-elements";
import Amplify, { API, Auth } from 'aws-amplify';
Amplify.configure({
AUTH: {
identityPoolId: 'identityPoolId',
region: 'us-east-1',
userPoolId: 'userPoolId',
userPoolWebClientId: 'userPoolWebClientId'
},
API: {
endpoints: [
{
name: "biotest1-prod",
endpoint: "endpointUrl"
},
]
}
});
class Home extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
notes: []
}
}
async componentDidMount() {
try {
this.session = await Auth.currentSession();
console.log(this.session);
} catch(e) { console.log('no session') }
const name = 'endpointUrl';
let path = '/notes';
let options = {
headers: {
Authorization: Auth.currentSession().idToken.jwtToken
}
}
API.get(name, path, options)
.then(response => console.log(response))
.catch(err => console.log(err));
}
userSignOut(){
Auth.signOut()
.then(data => {
console.log(data)
const { navigate } = this.props.navigation;
this.props.navigation.navigate("SignIn");
})
.catch(err => console.log(err));
}
render() {
return (
<View style={styles.container}>
<View style={styles.buttonView}>
<Button
buttonStyle={styles.btn}
title="SIGN OUT"
onPress={() => this.userSignOut()}
/>
</View>
<Text style={styles.text}>
This is the Home Page.
</Text>
</View>
);
}
}
export default Home;
推荐答案
我正在调用endpointUrl而不是api的名称. EndpointUrl进入您的amplify.configure.要手动配置,我使用了以下方法:
I was calling the endpointUrl instead of the api's name. The endpointUrl goes into your amplify.configure. To manually configure I used this:
Amplify.configure({
Auth: {
identityPoolId: 'us-east-1:=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx', // REQUIRED - Amazon Cognito Identity Pool ID
region: 'us-east-1', // REQUIRED - Amazon Cognito Region
userPoolId: 'us-east-x_xxxxxxxxx', // OPTIONAL - Amazon Cognito User Pool ID
userPoolWebClientId: 'xxxxxxxxxxxxxxxxxxxxxxxxxx', // OPTIONAL - Amazon Cognito Web Client ID
},
API: {
endpoints: [
{
name: "api-name",
endpoint: "your api endpoint",
service: "your service",
region: "us-east-1"
}
]
}
});
您可以在aws控制台中找到您的api网关信息.希望这会有所帮助.
You can find your api gateway information in aws console. Hope this helps.
这篇关于带有选项未定义错误的AWS放大api.get federateInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!