react-native - 我如何在原生反应中使用 aws amplify cognito?
问题描述
我正在尝试将 AWS 身份验证功能添加到应用程序。我已将配置添加到已经具有 graphql 和 pubsub 配置的文件中,并且我正在
Amplify.configure({ ...config.GraphQL, Auth: config.Auth })
调用App.js。在尝试使用注册时,我在日志中收到以下错误[NoUserPoolError: Authentication Error]
。
验证码
import { Auth } from 'aws-amplify';
...
Auth.signUp({
username: email,
password,
attributes: {
email // optional
// other custom attributes
},
validationData: [] //optional
})
.then(data => console.log(data))
.catch(err => console.log('Error:Auth.signUp ', err));
我的配置如下
Auth: {
IdentityPoolId: 'xxxxxxxx',
identityPoolId: 'xxxxxxxx',
Region: 'xxxxxxxx',
region: 'xxxxxxxx',
RoleArn: 'xxxxxxxx',
UserPoolId: 'xxxxxxxx',
ClientId: 'xxxxxxxx'
},
GraphQL:{
//config for graphql
}
在应用程序中,我得到如下红屏。
我还没有尝试过amplify push
。
解决方案
所以我发现了这个问题,所以回答我自己的问题。问题出在配置中。应该是这样的。
Auth: {
IdentityPoolId: 'xxxxxxxx',
identityPoolId: 'xxxxxxxx',
Region: 'xxxxxxxx',
region: 'xxxxxxxx',
RoleArn: 'xxxxxxxx',
userPoolId: 'xxxxxxxx', // this was previously UserPoolId
userPoolWebClientId: 'xxxxxxxx', // this was previously ClientId
authenticationFlowType:'xxxxxxx'
},
GraphQL:{
//config for graphql
}
推荐阅读
- r - R中递归解决方案的迭代
- algorithm - Haskell 中的 Floyd-Warshall 算法
- php - 在输入/文本区域内编写 HTML / PHP 代码
- python - 关于 tf.keras SGD 批处理
- javascript - 无需单击按钮的表单的 JavaScript 功能
- c# - 使用 C# 以编程方式获取 Mac OS 上已安装程序的列表
- python - 使用 tensorflow 和 TFBertForNextSentencePrediction 在特定语料库上进一步训练 bert
- javascript - 参数声明本身
- visual-studio-code - 在 Visual Code 终端上找到 nvm 和 gulp,但在 linux 终端上没有
- networking - 测验中的子网问题需要解释(见图)