未创建AWS Cognito自定义属性

编程入门 行业动态 更新时间:2024-10-27 04:30:57
本文介绍了未创建AWS Cognito自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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自定义属性

本文发布于:2023-11-16 04:42:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   属性   AWS   Cognito

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!