Amplify-js: Would like to better understand the benefits of using AWS Amplify Authentication.

Created on 22 Nov 2017  路  2Comments  路  Source: aws-amplify/amplify-js

This looks like an awesome new tool. Can you help me answer the following question?

When not using aws-amplify-react or aws-amplify-react-native what is the main benefit of using the AWS Amplify Auth module over using Cognito directly?

Most helpful comment

Goal of AWS Amplify Auth is to make common tasks easy, let developer focus on their business differentiators.

Amazon Cognito signUp:

var poolData = {
        UserPoolId : '...', // Your user pool id here
        ClientId : '...' // Your client id here
    };
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

    var attributeList = [];

    var dataEmail = {
        Name : 'email',
        Value : '[email protected]'
    };

    var dataPhoneNumber = {
        Name : 'phone_number',
        Value : '+15555555555'
    };
    var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
    var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);

    attributeList.push(attributeEmail);
    attributeList.push(attributePhoneNumber);

    userPool.signUp('username', 'password', attributeList, null, function(err, result){
        if (err) {
            alert(err);
            return;
        }
        cognitoUser = result.user;
        console.log('user name is ' + cognitoUser.getUsername());
    });

AWS Amplify signUp:

Amplify.configure(aws_exports);

Auth.signUp('username', 'password', '[email protected]', '+15555555555')
    .then(user => console.log(user))
    .catch(err => console.log(err));

All 2 comments

Goal of AWS Amplify Auth is to make common tasks easy, let developer focus on their business differentiators.

Amazon Cognito signUp:

var poolData = {
        UserPoolId : '...', // Your user pool id here
        ClientId : '...' // Your client id here
    };
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

    var attributeList = [];

    var dataEmail = {
        Name : 'email',
        Value : '[email protected]'
    };

    var dataPhoneNumber = {
        Name : 'phone_number',
        Value : '+15555555555'
    };
    var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
    var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);

    attributeList.push(attributeEmail);
    attributeList.push(attributePhoneNumber);

    userPool.signUp('username', 'password', attributeList, null, function(err, result){
        if (err) {
            alert(err);
            return;
        }
        cognitoUser = result.user;
        console.log('user name is ' + cognitoUser.getUsername());
    });

AWS Amplify signUp:

Amplify.configure(aws_exports);

Auth.signUp('username', 'password', '[email protected]', '+15555555555')
    .then(user => console.log(user))
    .catch(err => console.log(err));

Amplify also manages AWS Credentials gathered from Amazon Cognito Federated Identities (the above example is for Amazon Cognito User Pools). For example Instead of following this process and then signing, such as sending requests to Amazon API Gateway, Amplify does this all under the covers for you.

Was this page helpful?
0 / 5 - 0 ratings