我正在尝试使用AWS Cognito SDK设置Cognito用户,但在向用户添加自定义属性时遇到问题。我确保变量名称完全匹配,并且应用程序允许对所有属性进行读/写。我的代码如下所示:
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; } }使用此代码,正确设置了name和phone_number属性但是没有is_driver。我试图使用adminGetUser获取所有用户的属性,但is_driver仍然没有出现。任何指导都将不胜感激!
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!
推荐答案我认为可能会发生这种情况,因为您将属性值作为数字传递给0。这只是服务的特殊性,属性被视为字符串进行验证。
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' };更多推荐
未创建AWS Cognito自定义属性
发布评论