简体   繁体   中英

AWS Cognito Custom Attributes Not Created

I am trying to setup a Cognito user using the AWS Cognito SDK and am having trouble adding custom attributes to a user. I have ensured that the variable names match up exactly and that the application allows read/write on all of the attributes. My code looks like this:

var attributeList = [];

var dataName = {
    Name: 'name',
    Value: name
};
var dataPhoneNumber = {
    Name: 'phone_number',
    Value: phone
};
var dataIsDriver = {
    Name: 'custom:is_driver',
    Value: 0
};

var attributeName = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataName);
var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);
var attributeIsDriver = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataIsDriver);


attributeList.push(attributeName);
attributeList.push(attributePhoneNumber);
attributeList.push(attributeIsDriver);

var username = generateUUID();
localStorage.setItem("username", username);

var userPool = getUserPool();
userPool.signUp(username, password, attributeList, null, function (err, result) {
    if (err) {
        alert(err);
        return;
    }
}

With this code, the name and phone_number attributes are being set correctly but there is no "is_driver." I've tried to use adminGetUser to get all of the user's attributes but is_driver still doesn't appear. Any guidance would be appreciated!

I think that might be happening because you are passing the attribute value as a number so 0. It's just a particularity of the service that attributes are treated as Strings for validation.

Can you try replacing that with the code below and see if it works.

var dataIsDriver = {
    Name: 'custom:is_driver',
    Value: '0'
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM