title: Amazon Cognito newPasswordRequired await for page load
body: <p>I am implementing Amazon Cognito User Pool authentication in my web app, and I ran in this problem - how to redirect user on newPasswordRequired callback to '/new-password' and await for inputs?</p>
  
  <p>So in other words, my expected flow is User logs in with temporary password(here I fire cognitoUser.authenitcateUser), after that I redirect user to '/new-password' route and user sees the new password form(newPasswordRequired callback is triggered here). </p>
  
  <p>Problem now is that SDK expects me to pass passwords in the newPassword callback but I don't know them yet(since the user will put it in new password form).</p>
  
  <p>Code: </p>
  
  <pre><code>async login(values) {
  const details = {
    Username: values.username,
    Password: values.password,
  };
  
  const authDetails = new AuthenticationDetails(details);
  const userData = {
    Username: details.Username,
    Pool: poolData,
  };
  
  const cognitoUser = await new CognitoUser(userData);
  await cognitoUser.authenticateUser(authDetails, {
    onSuccess: (result) =&gt; {
      console.log(userData);
      axios.defaults.headers.common.Authorization = result.getIdToken().getJwtToken();
      browserHistory.push('/entities');
    },
    onFailure: (error) =&gt; {
      console.log(userData);
      throw new Error(error);
    },
    newPasswordRequired: () =&gt; {
      browserHistory.push('/new-password');
      console.log(cognitoUser);
      console.log(cognitoUser.getAuthenticationFlowType(), 'YOU NEED TO CHANGE PASSWORD');
      const userData = {
        Username: cognitoUser.username,
        Pool: poolData,
      };
      cognitoUser.completeNewPasswordChallenge(
        values.newPassword,
        {},
        {
          onSuccess: (user) =&gt; {
            console.log('success', user);
          },
          onFailure: (error) =&gt; {
            console.log(error);
          },
        },
      );
    },
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Another thing I tried was to create separate method which is responsible for calling cognitoUser.completeNewPasswordChallenge but then User Pool thinks that I am not authenticated. </p>
  
  <p>My react component looks like this:</p>
  
  <pre><code>&lt;form onSubmit={this.props.handleSubmit(AWSApi.login.bind(this))}&gt;&lt;/form&gt;
  </code></pre>