简体   繁体   English

未创建AWS Cognito自定义属性

[英]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. 我正在尝试使用AWS Cognito SDK设置Cognito用户,并且无法向用户添加自定义属性。 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." 使用此代码,可以正确设置name和phone_number属性,但是没有“ is_driver”。 I've tried to use adminGetUser to get all of the user's attributes but is_driver still doesn't appear. 我尝试使用adminGetUser来获取用户的所有属性,但是is_driver仍然没有出现。 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. 我认为可能会发生这种情况,因为您将属性值传递为一个数字,所以为0。将属性视为用于验证的字符串只是服务的特殊性。

Can you try replacing that with the code below and see if it works. 您可以尝试将其替换为下面的代码,看看是否可行。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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