amazon-cognito-identity-js - forgot password for Invalid User

Viewed 200

I am using amazon-cognito-identity-js node module for forgot password implementation. Below is my service code.

 var userData = {
    Username: '<username>',
    Pool: '<userpool id>',
  }

var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData)
  return new Promise(function (resolve, reject) {
    cognitoUser.forgotPassword({
      onSuccess: function (data) {
        resolve({
          statusCode: 200, response: {
            ForgotPasswordResponse: {
              Status: 'Success',
              Destination: data.CodeDeliveryDetails.Destination
            },
          }
        })
      },
      onFailure: function (err) {
        resolve({
          statusCode: 400, response: {
            ForgotPasswordResponse: {
              Status: 'failure',
              Error: err.message
            },
          }
        })
      }
    });
  })
}

If I pass username which is not in pool, code still goes in onSuccess function and have no idea to which destination it is sending verification code. Same thing happens if I pass username whose status in cognito userpool is FORCE_CHANGE_PASSWORD. Kindly suggest to handle this scenario.

0 Answers
Related