Javascript aws amplify api.get federateInfo带有未定义的选项错误
我正在玩aws放大和反应本机。我正在尝试在主屏幕上进行api.get调用,但一直遇到错误:Javascript aws amplify api.get federateInfo带有未定义的选项错误,javascript,react-native,aws-api-gateway,aws-amplify,Javascript,React Native,Aws Api Gateway,Aws Amplify,我正在玩aws放大和反应本机。我正在尝试在主屏幕上进行api.get调用,但一直遇到错误: 获取项目:键是federatedInfo,选项未定义 我正在调用aws api网关dynamodb。我一直在研究文档的修复,但大多数都指向使用HOC with authenticator。我不想这样做,因为我已经定制了登录/注册/确认屏幕。在正确的方向上提供任何帮助或只是一点帮助都会很好。这是我的主页。屏幕代码: import React, { Component } from 'react'; impo
获取项目:键是federatedInfo,选项未定义
我正在调用aws api网关dynamodb。我一直在研究文档的修复,但大多数都指向使用HOC with authenticator。我不想这样做,因为我已经定制了登录/注册/确认屏幕。在正确的方向上提供任何帮助或只是一点帮助都会很好。这是我的主页。屏幕代码:
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;
import React,{Component}来自'React';
从“react native”导入{View,Text,StyleSheet};
从“react native elements”导入{Button};
从“aws Amplify”导入Amplify,{API,Auth};
放大({
认证:{
identityPoolId:“identityPoolId”,
地区:'us-east-1',
userPoolId:'userPoolId',
userPoolWebClientId:'userPoolWebClientId'
},
API:{
端点:[
{
名称:“生物测试1产品”,
端点:“端点URL”
},
]
}
});
类Home扩展组件{
建造师(道具){
超级(道具);
此.state={
加载:对,
注:[]
}
}
异步组件didmount(){
试试{
this.session=wait Auth.currentSession();
console.log(this.session);
}catch(e){console.log('no session')}
const name='endpointUrl';
让path='/notes';
让选项={
标题:{
授权:Auth.currentSession().idToken.jwtToken
}
}
获取(名称、路径、选项)
.then(response=>console.log(response))
.catch(err=>console.log(err));
}
userSignOut(){
Auth.signOut()
。然后(数据=>{
console.log(数据)
const{navigate}=this.props.navigation;
这个.props.navigation.navigate(“登录”);
})
.catch(err=>console.log(err));
}
render(){
返回(
this.userSignOut()}
/>
这是主页。
);
}
}
导出默认主页;
我调用的是endpointUrl,而不是api的名称。endpointUrl进入amplify.configure。要手动配置,我使用以下方法:
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网关信息。希望这能有所帮助。我仍然会发现错误。我认为这与我的API无关,因为我没有使用API。有什么想法吗?@JosephAstrahan如果你不使用API,只是进行身份验证,我会在你的用户池中查看你的联合身份我在那里寻找什么,我在任何登录之前得到错误信息attempted@JosephAstrahan请打开一个问题并发布代码。我会尽力帮忙的