reactjs - 是否可以在 React 应用程序中单独使用 Amplify Auth?

标签 reactjs amazon-web-services aws-amplify amplifyjs

我在这方面有点新。我有一个基于 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);
    }

现在,当我尝试在我的用户池中注册一个用户时,该用户已创建并且验证邮件也已发送。但在客户端,我收到此错误 -

enter image description here
谁能告诉我是否有可能我正在尝试什么?你认为我只能使用 Authaws 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/

相关文章:

aws-amplify - gatsby 图像在 aws amplify 中托管时不显示,但在本地开发/netlify/gatsby 云上正常

javascript - 区域缺失错误 - AWS Amplify React

amazon-web-services - 亚马逊网络服务 - 检索愿望 list

reactjs - 功能组件嵌套 vs. props

javascript - 使用react-router加载器,如果在加载器中完成的提取导致401,我如何重定向到登录路由?

javascript - React Hooks - 滚动

java - ec2 AWS 微实例上的 java 堆问题

amazon-web-services - AWS账户与Amazon消费者账户

graphql - 如何防止访问 Amplify graphql 公共(public) API 中的某些字段

javascript - React Router VS 条件渲染