aws-lambdaamazon-cognitoaws-userpools

AWS Cognito SignUP with custom Attributes in node js causing error


I am trying to build Signup through a lambda function with AWS user pool where I added a custom attribute called type. When I am sending a type value with signup, an error "A client attempted to write unauthorized attribute" is populating.

I am using 'amazon-cognito-identity-js' package to save data. Here is my code snippet


        const attributeList = [];
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"name",Value:user.username}));
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"custom:type",Value:'asd'}));
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"gender",Value:user.gender}));
        attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({Name:"email",Value:user.email}));

        userPool.signUp(user.email, user.password, attributeList, null, function(err, result){
            if (err) {
                return reject(err);
            }
           return resolve(result);
        });**strong text**

Solution

  • After that you added a new attribute, you should select the user attributes this app client can read and write.

    Steps:

    1. Go to your Cognito User Pool page
    2. Click on the "App Client" from the left side menu
    3. Click on the "Set attribute read and write permissions"
    4. Make sure you added the necessary(read/write) permissions for the needed attribute

    enter image description here enter image description here