将用户电话号码属性更新为 AWS cognito 并使用 node.js

问题描述

任何人都可以帮助我满足上述要求吗?

我们必须更新 AWS cognito 中的 phone_number 属性并发送 SMS MFA 以确认手机号码。并且我们还必须验证发送给用户的代码。

解决方法

如果您在设置中启用了电话验证,Cognito 会自动执行此操作。只需运行 UpdateUserAttributes 函数并设置一个新的电话号码即可。

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UpdateUserAttributes.html

,

当然可以。您需要使用 AWS 开发工具包。

const AWS = require('aws-sdk');
const config = require('./config'); 

function updateAttribute(params) {
    AWS.config.update({
        'region' : config.AWSConfig.region,'accessKeyId': config.AWSConfig.accessKeyId,'secretAccessKey': config.AWSConfig.secretAccessKey
    });
    let cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();

    let parameters = { UserPoolId : config.userPoolDetails.userPoolId,Username : params.userName,UserAttributes : [
        {
            'Name': params.nameOfAttribute,'Value': params.newValueOfAttribute
        },]}
    
    cognitoIdentityServiceProvider.adminUpdateUserAttributes(parameters,function (err,result) {
        if(err)
        console.log(err);
        else
        console.log("Attribute updated successfully");
    })
}

let params = {
    userName : 'username',nameOfAttribute : 'name',newValueOfAttribute : 'Sachin'
}

updateAttribute(params);

您甚至可以像这样添加新属性。

您可以在此处阅读更多信息:https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...