Reputation: 35
Can any only help me with the above requirement?
We have to update the phone_number attribute in AWS cognito and send a SMS MFA to confirm the mobile number. and also we have to verify the code sent to the user.
Upvotes: 1
Views: 4724
Reputation: 411
Yes ofcourse. You need to use AWS SDK.
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);
You can even add new attribute like this.
You can read more here : https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html
Upvotes: 2
Reputation: 4480
Cognito does this automatically if you have phone verification enabled in settings. Just run the UpdateUserAttributes function and set a new phone number.
Upvotes: 0