Friday, 12 May 2017

cognito pool - failed to signup a user

I am trying to build a user management based on cognito user pool. I am using nodesjs + express for the backend, all the operation to cognito will be done from the nodejs.

my signup route is

app.post('/signup', (req, res) => {
let userName = req.body.userName;
let email = req.body.email;
let familyName = req.body.familyName;
let password = req.body.password;

let attributeList = [];

let dataEmail = {
    Name: 'email',
    Value: email
};

let name = {
    Name: 'name',
    Value: userName
};

let familyname = {
    Name: 'family_name',
    Value: familyName
};

let attributeEmail = new AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);
let attributeName = new AmazonCognitoIdentity.CognitoUserAttribute(name);
let attributeFamilyName = new AmazonCognitoIdentity.CognitoUserAttribute(familyname);

attributeList.push(attributeEmail);
attributeList.push(attributeName);
attributeList.push(familyname);

let userPool = new CognitoUserPool(poolData);
userPool.signUp(email, password, attributeList, null, (err, result) => {
    if (err) {
        console.log(`got error during signup ${err}`);
        res.sendStatus(500);
    } else {
        let cognitoUser = result.user;
        console.log('user name is ' + cognitoUser.getUsername());
        res.sendStatus(200);
    }

   });

});

however I am getting a failure and cannot find how to over come it the error is missing parameter:

got error during signup MissingRequiredParameter: Missing required key 'Username' in params



via li-raz

No comments:

Post a Comment