我在这方面有点新。我有一个基于 react 的 Web 应用程序,我们一直在使用 AWS cognito 进行身份验证。我正在使用 amazon-cognito-identity-js
在用户池中注册用户并登录。
现在我试图用 aws amplify auth
替换那个库因为它干净的界面。但我不想完成设置过程(放大初始化和所有内容),我想像我使用的那样使用它 amazon-cognito-identity-js
.
这是我到目前为止所做的,
我已经配置了 Amplify Auth
在我的 app.js
文件 -
import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'my id pool',
// REQUIRED - Amazon Cognito Region
region: 'my-region',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'my-userpool',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'my app client',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: true,
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_SRP_AUTH'
}
});
这是我在
Registration
中注册时所做的工作成分 -const { username, password, email, name } = this.state;
try {
const result = await Auth.signUp({
username,
password,
attributes: {
'name': name,
'email': email,
'phone_number': '',
},
});
this.setState({showVerificationCode: true});
} catch(e) {
console.log(e);
}
现在,当我尝试在我的用户池中注册一个用户时,该用户已创建并且验证邮件也已发送。但在客户端,我收到此错误 -
谁能告诉我是否有可能我正在尝试什么?你认为我只能使用
Auth
的 aws amplify
在客户端隔离,没有任何云或任何东西,只需用户注册和登录用户池?
最佳答案
That is an issue for this.
您猜对了,AWS Amplify 正在添加分析。但不是像您那样使用禁用的 Analytics 配置它,建议的修复方法是使用 modular imports:
import Amplify from '@aws-amplify/core';
import Auth from '@aws-amplify/auth';
如果你这样做
import Amplify from 'aws-amplify';
它会自动加载
Auth
,这会导致错误。
关于reactjs - 是否可以在 React 应用程序中单独使用 Amplify Auth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925394/