繁体   English   中英

未创建AWS Cognito自定义属性

[英]AWS Cognito Custom Attributes Not Created

我正在尝试使用AWS Cognito SDK设置Cognito用户,并且无法向用户添加自定义属性。 我确保变量名完全匹配,并且应用程序允许对所有属性进行读/写。 我的代码如下所示:

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

使用此代码,可以正确设置name和phone_number属性,但是没有“ is_driver”。 我尝试使用adminGetUser来获取用户的所有属性,但是is_driver仍然没有出现。 任何指导将不胜感激!

我认为可能会发生这种情况,因为您将属性值传递为一个数字,所以为0。将属性视为用于验证的字符串只是服务的特殊性。

您可以尝试将其替换为下面的代码,看看是否可行。

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

暂无
暂无

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

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