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

Ras*_*rov 5 amazon-web-services amplifyjs reactjs aws-amplify

我对此有点陌生。我有一个基于 React 的 Web 应用程序,我们一直在使用 AWS cognito 进行身份验证。我用来amazon-cognito-identity-js在用户池中注册用户并进行登录。

现在我正在尝试替换该库,aws amplify auth因为它的界面干净。但我不想经历设置过程(放大 init 和所有内容),我想像我使用的那样使用它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'
    }
});
Run Code Online (Sandbox Code Playgroud)

这是我在组件中注册所做的事情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);
    }
Run Code Online (Sandbox Code Playgroud)

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

在此输入图像描述 谁能告诉我我正在尝试的事情是否可能?Auth您是否认为我只能在客户端单独使用,aws amplify而无需任何云或任何东西来仅在用户池中进行用户注册和登录?

J. *_*ers 1

这是一个问题。

您猜对了,AWS Amplify 正在添加分析。但建议的修复方法是使用模块化导入,而不是像您那样配置禁用的 Analytics:

import Amplify from '@aws-amplify/core';
import Auth from '@aws-amplify/auth';
Run Code Online (Sandbox Code Playgroud)

如果你这样做

import Amplify from 'aws-amplify';
Run Code Online (Sandbox Code Playgroud)

它会自动加载Auth,这会导致错误。