我正在尝试使用 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;
}
}
使用此代码,名称和电话号码属性已正确设置,但没有“is_driver”。我尝试使用 adminGetUser 来获取用户的所有属性,但 is_driver 仍然没有出现。任何指导将不胜感激!
最佳答案
我认为这可能会发生,因为您将属性值作为数字传递,所以 0。属性被视为字符串进行验证,这只是服务的一个特殊性。
您可以尝试用下面的代码替换它,看看它是否有效。
var dataIsDriver = {
Name: 'custom:is_driver',
Value: '0'
};
关于javascript - 未创建 AWS Cognito 自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43378871/