4

我在这方面有点新意。我有一个基于反应的网络应用程序,我们一直在使用 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);
    }

现在,当我尝试在我的用户池中注册用户时,会创建用户并发送验证邮件。但是在客户端我收到了这个错误-

在此处输入图像描述 谁能告诉我是否有可能我正在尝试什么?您是否认为我只能在客户端单独使用Authofaws amplify而没有任何云或任何东西来仅用户注册和登录用户池?

4

2 回答 2

1

好的,我已经弄清楚为什么会发生错误。我写下来作为答案,以便偶然发现此问题的人可以得到答案-

似乎默认aws amplify使用该Analytic服务并尝试记录“身份验证”事件。所以我需要在配置中禁用它 -

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'
    },

    Analytics: {
        disabled: true,
    }
});
于 2019-07-08T06:27:35.340 回答
1

这是一个问题。

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

import Amplify from '@aws-amplify/core';
import Auth from '@aws-amplify/auth';

如果你这样做

import Amplify from 'aws-amplify';

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

于 2019-07-08T11:24:16.987 回答