Skip to content

Instantly share code, notes, and snippets.

@itsrajverma
Forked from prasadjay/changePwdCognito.js
Created July 15, 2019 08:01
Show Gist options
  • Select an option

  • Save itsrajverma/29e349c11f044ac0f9c2aeedabdc61a6 to your computer and use it in GitHub Desktop.

Select an option

Save itsrajverma/29e349c11f044ac0f9c2aeedabdc61a6 to your computer and use it in GitHub Desktop.
Change-Password-Cognito
function ChangePassword(username, password, newpassword) {
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails({
Username: username,
Password: password,
});
var userData = {
Username: username,
Pool: userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
cognitoUser.changePassword(password, newpassword, (err, result) => {
if (err) {
console.log(err);
} else {
console.log("Successfully changed password of the user.");
console.log(result);
}
});
},
onFailure: function (err) {
console.log(err);
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment