问题
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;
回答1:
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"
}
]
}
});
You can find your api gateway information in aws console. Hope this helps.
来源:https://stackoverflow.com/questions/48953078/aws-amplify-api-get-federateinfo-with-options-undefined-error