首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >aws-amplify api.get federateInfo with options undefined error

aws-amplify api.get federateInfo with options undefined error
EN

Stack Overflow用户
提问于 2018-02-24 01:16:39
回答 1查看 1.2K关注 0票数 4

我正在尝试使用aws-amplify和react-native。我正尝试在主屏幕上进行api.get调用,但一直遇到错误:

Get item:键为federatedInfo,选项未定义

我正在调用一个aws-api-gateway dynamodb。我一直在寻找文档的修复,但大多数都指向使用HOC withAuthenticator。我不想这样做,因为我已经定制了登录/登录/确认屏幕。任何帮助,或者只是在正确的方向上的一个点,都会很好。下面是我的Home.screen代码:

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2018-02-28 05:18:49

我调用的是endpointUrl,而不是api的名称。endpointUrl将进入您的amplify.configure。为了手动配置,我使用了以下命令:

代码语言:javascript
复制
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网关信息。希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48953078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档