AWS Cognito,检索旧的编辑自定义值
创始人
2024-11-15 08:30:08
0

要检索旧的编辑自定义值,您可以使用 AWS Cognito 的管理 API 来获取用户的属性(包括自定义属性)。

以下是一个示例代码,演示如何使用 AWS SDK for JavaScript(Node.js)来检索用户的旧编辑自定义值:

const AWS = require('aws-sdk');

AWS.config.update({ region: 'YOUR_REGION' });

const cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();

const getUserAttributes = async (userPoolId, username) => {
  const params = {
    UserPoolId: userPoolId,
    Username: username
  };

  try {
    const data = await cognitoIdentityServiceProvider.adminGetUser(params).promise();
    return data.UserAttributes;
  } catch (error) {
    console.error(error);
    throw error;
  }
};

const getCustomAttributeValue = (userAttributes, attributeName) => {
  const attribute = userAttributes.find(attr => attr.Name === attributeName);
  return attribute ? attribute.Value : undefined;
};

// Usage example
const userPoolId = 'YOUR_USER_POOL_ID';
const username = 'USER_USERNAME';
const customAttributeName = 'YOUR_CUSTOM_ATTRIBUTE_NAME';

getUserAttributes(userPoolId, username)
  .then(userAttributes => {
    const customAttributeValue = getCustomAttributeValue(userAttributes, customAttributeName);
    console.log(`User's custom attribute value: ${customAttributeValue}`);
  })
  .catch(error => {
    console.error(error);
  });

请确保将 YOUR_REGION 替换为您的 AWS 区域,YOUR_USER_POOL_ID 替换为您的用户池 ID,USER_USERNAME 替换为要检索属性的用户的用户名,YOUR_CUSTOM_ATTRIBUTE_NAME 替换为您的自定义属性的名称。

此示例使用 adminGetUser 方法从 Cognito 用户池中检索用户的属性。检索到的属性将作为数组返回,然后使用 getCustomAttributeValue 函数找到所需的自定义属性的值。

希望这可以帮助到您!

相关内容

热门资讯

透明私人局(wepoker)外... wepoker赢率提升策略‌;透明私人局(wepoker)外挂透明挂辅助工具(辅助挂)透视辅助(揭秘...
透视好友(德州ai智能)外挂透... 透视好友(德州ai智能)外挂透明挂辅助工具(辅助挂)德州ai机器人(有挂教学)-哔哩哔哩;德州ai智...
推荐十款!德州之星软件(wep... 推荐十款!德州之星软件(wepoke)外挂透明挂辅助脚本(透视)科技教程(有挂教学)-哔哩哔哩;(需...
透明挂透视(wepOke)外挂... 透明挂透视(wepOke)外挂透明挂辅助APP(透视)其实真的有挂(2025已更新)(哔哩哔哩);w...
玩家必看科普(WepoKe)外... WePoke高级策略深度解析‌;玩家必看科普(WepoKe)外挂透明挂辅助工具(透视)辅助透视(发现...
十分钟了解!aapoker后台... 十分钟了解!aapoker后台(wEPoke)外挂透明挂辅助APP(辅助挂)分享教程(讲解有挂)-哔...
传递经验(云扑克德州)外挂透明... 传递经验(云扑克德州)外挂透明挂辅助app(透视)发牌规律(存在有挂)-哔哩哔哩;建议优先通过云扑克...
一分钟了解(德扑ai操作)外挂... 一分钟了解(德扑ai操作)外挂透明挂辅助工具(辅助挂)透视辅助(新版有挂)-哔哩哔哩1、很好的工具软...
今日焦点(德扑计算)外挂透明挂... 今日焦点(德扑计算)外挂透明挂辅助脚本(辅助挂)竟然真的有挂(2020已更新)(哔哩哔哩);亲,其实...
透明肯定!微扑克网页版(weP... 透明肯定!微扑克网页版(wePoKe)外挂透明挂辅助工具(辅助挂)系统教程(有挂规律)-哔哩哔哩1、...