rahulje9
rahulje9

Reputation: 162

How can i use aws amplify cognito in react native?

I'm trying to add AWS authentication functionality to the app. I have added the config to a file that already has graphql and pubsub config, and I'm calling Amplify.configure({ ...config.GraphQL, Auth: config.Auth }) in the App.js. while trying to use signup I'm getting the following error in the log [NoUserPoolError: Authentication Error].

code for auth

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));

My configuration is as follows

    Auth: {
        IdentityPoolId: 'xxxxxxxx',
        identityPoolId: 'xxxxxxxx',
        Region: 'xxxxxxxx',
        region: 'xxxxxxxx',
        RoleArn: 'xxxxxxxx',
        UserPoolId: 'xxxxxxxx',
        ClientId: 'xxxxxxxx'
    },
    GraphQL:{
             //config for graphql
    }

and in the app, I'm getting the red screen as follows.

enter image description here

I haven't tried the amplify push yet.

Upvotes: 1

Views: 523

Answers (1)

rahulje9
rahulje9

Reputation: 162

SO I found out the issue, so answering my own question. The issue was in the config. It should have been as follows.

    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
    }

Upvotes: 1

Related Questions