Created
June 5, 2018 17:17
-
-
Save prasadjay/40f565de5ce997ee46b6415e743f4a76 to your computer and use it in GitHub Desktop.
Change-Password-Cognito
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
You may need to get the current user details first if you are getting a callback or user is not authenticated error:
more details here