Preet Saxena
Preet Saxena

Reputation: 127

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**

Upvotes: 2

Views: 2163

Answers (2)

Preet Saxena
Preet Saxena

Reputation: 127

In addition to the above answer, sometimes custom attributes may take time to reflect under clients. Because I noticed it around 15 mins but after 1 hour it was there.

Upvotes: 1

CyberEternal
CyberEternal

Reputation: 2545

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

Upvotes: 4

Related Questions