Amplify-js: Auth: signIn always returns { challengeName : "NEW_PASSWORD_REQUIRED" }

Created on 21 Sep 2018  路  9Comments  路  Source: aws-amplify/amplify-js

Describe the bug
The Auth.signIn() function always returns a new password challenge in the user object:
{ challengeName : "NEW_PASSWORD_REQUIRED" }, even after doing Auth.completeNewPassword()

The user status is "CONFIRMED" in the AWS Cognito user list.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new user
  2. Start sign in flow:
signIn(username, password )
      .then(user => {
        if ((user.challengeName == 'NEW_PASSWORD_REQUIRED')) {
          this._setCompletePasswordState(user);
        } else {
          this.props.onSignIn(user);
        }
      })
  1. Start complete password flow:
completeNewPassword(params)
      .then(response => {
        console.log('password changed: ', response);
        this.props.onSignIn();
      })
  1. Log out
  2. Log back in and inspect user payload

Expected behavior
I think the challengeName should be empty

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version: 68

Additional context
I am currently getting around this by running checkCurrentAuth() after signIn() and using a catch to detect if the user needs to reset their password:

 signIn({ username, password })
      .then(user => {
        checkCurrentAuth()
          .then(() => {
            this.props.onSignIn(user);
          })
          .catch(() => {
            this._setCompletePasswordState(user);
          });
      })
Auth Cognito pending-close-response-required

Most helpful comment

You appear to be asigning the value to user.challengeName instead of reading it.

I think if (user.challengeName = 'NEW_PASSWORD_REQUIRED') should be if (user.challengeName === 'NEW_PASSWORD_REQUIRED') ?

See: https://aws-amplify.github.io/docs/js/authentication#complete-new-password

All 9 comments

@zyzski after finishing the auth challenge, can you go to the Cognito Console to see if the user status is changed from FORCE_NEW_PASSWORD to CONFIRMED?

The user status is CONFIRMED in the AWS Cognito console

@zyzski So the first time when you sign in, you got to change the password and after that your user status is CONFIRMED in the cognito console. But the next time when you sign in again, the response from Cognito still contains the challenge right?

yes. i was able to complete the reset password flow but the challenge response never goes away, so I can't determine when to correctly prompt for a reset

@zyzski Can you pm me your some of your sample requests? like request id with timestamp, or har file

You appear to be asigning the value to user.challengeName instead of reading it.

I think if (user.challengeName = 'NEW_PASSWORD_REQUIRED') should be if (user.challengeName === 'NEW_PASSWORD_REQUIRED') ?

See: https://aws-amplify.github.io/docs/js/authentication#complete-new-password

@zyzski Are you still experiencing this issue with the latest aws-amplify?

@zyzski - Closing this issue due to inactivity. If needed feel free to repost, but include the version of aws-amplify you are using.

You appear to be asigning the value to user.challengeName instead of reading it.

I think if (user.challengeName = 'NEW_PASSWORD_REQUIRED') should be if (user.challengeName === 'NEW_PASSWORD_REQUIRED') ?

See: https://aws-amplify.github.io/docs/js/authentication#complete-new-password

You solved my issue too! Thank you!! Dumb mistake on my part.

Was:
cognitoUser.challengeName = 'Enabled / FORCE_CHANGE_PASSWORD'

Now:
cognitoUser.challengeName === 'Enabled / FORCE_CHANGE_PASSWORD'

Was this page helpful?
0 / 5 - 0 ratings