AWS Cognito Custom Attributes Not Created

坚强是说给别人听的谎言 提交于 2019-12-31 05:21:13

问题


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!


回答1:


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'
};


来源:https://stackoverflow.com/questions/43378871/aws-cognito-custom-attributes-not-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!