Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cognitoUser.forgotPassword({
- onSuccess: function (result) {
- console.log('call result: ' + result);
- },
- onFailure: function(err) {
- alert(err);
- },
- inputVerificationCode() {
- var verificationCode = prompt('Please input verification code ' ,'');
- var newPassword = prompt('Enter new password ' ,'');
- cognitoUser.confirmPassword(verificationCode, newPassword, this);
- }
- });
- export function resetPassword(username) {
- // const poolData = { UserPoolId: xxxx, ClientId: xxxx };
- // userPool is const userPool = new AWSCognito.CognitoUserPool(poolData);
- // setup cognitoUser first
- cognitoUser = new AWSCognito.CognitoUser({
- Username: username,
- Pool: userPool
- });
- // call forgotPassword on cognitoUser
- cognitoUser.forgotPassword({
- onSuccess: function(result) {
- console.log('call result: ' + result);
- },
- onFailure: function(err) {
- alert(err);
- },
- inputVerificationCode() { // this is optional, and likely won't be implemented as in AWS's example (i.e, prompt to get info)
- var verificationCode = prompt('Please input verification code ', '');
- var newPassword = prompt('Enter new password ', '');
- cognitoUser.confirmPassword(verificationCode, newPassword, this);
- }
- });
- }
- // confirmPassword can be separately built out as follows...
- export function confirmPassword(username, verificationCode, newPassword) {
- cognitoUser = new AWSCognito.CognitoUser({
- Username: username,
- Pool: userPool
- });
- return new Promise((resolve, reject) => {
- cognitoUser.confirmPassword(verificationCode, newPassword, {
- onFailure(err) {
- reject(err);
- },
- onSuccess() {
- resolve();
- },
- });
- });
- }
- //validation of input from form
- req.checkBody('email', 'Username is required').notEmpty();
- req.checkBody('password', 'Password is required').notEmpty();
- req.checkBody('confirmationcode', 'Confirmation Code is required').notEmpty();
- var confirmationCode = req.body.confirmationcode;
- var password = req.body.password;
- var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
- var userData = {
- Username: req.body.email,
- Pool: userPool
- };
- var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
- cognitoUser.confirmPassword(confirmationCode, password, {
- onFailure(err) {
- console.log(err);
- },
- onSuccess() {
- console.log("Success");
- },
- });
Add Comment
Please, Sign In to add comment