首页 > 解决方案 > 我如何在原生反应中使用 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

标签: react-nativeamazon-cognitoaws-amplify

解决方案


所以我发现了这个问题,所以回答我自己的问题。问题出在配置中。应该是这样的。

    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
    }

推荐阅读