我正在玩 aws-amplify 和 react-native。我正在尝试在我的主屏幕上进行 api.get 调用,但一直遇到错误:
获取项目:键是 federatedInfo,选项未定义
我正在调用 aws-api-gateway dynamodb。我一直在寻找文档的修复,但大多数都指向使用 HOC withAuthenticator。我不想这样做,因为我已经定制了登录/登录/确认屏幕。任何帮助或只是正确方向的一点都会很棒。这是我的 Home.screen 代码:
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;