aws-amplify api.get federateInfo with options undefined error

邮差的信 提交于 2019-12-14 01:31:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!