question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling forced password reset in custom authentication is broken

See original GitHub issue

Describe the bug In the console I have set my user to RESET_REQUIRED. Calling Auth.signIn throws an error “PasswordResetRequiredException”. The problem is that Auth.sendCustomChallengeAnswer requires the user object from signin. I don’t have access to the user object from the try catch.

To Reproduce

const login = async ({ username, password }) => {
    try {
      const user = await Auth.signIn(username, password);
      console.log('login -> user', user);
      setUser(user);
     ....
    } catch(err) {
      console.log('login -> err', err);
      if (err.code === 'PasswordResetRequiredException') {
        setNewPasswordRequired(true);
      } else if (err.code === 'UserNotConfirmedException') {
        props.navigation.navigate('VerifyEmail', { username });
      } else {
        setError(err.message);
      }
    }
  };

I then show an update password form, then call:

const updatePassword = async ({ password }) => {
    try {
      const result = await Auth.completeNewPassword(user, password);
      console.log('updatePassword -> user', result);
      setUser(result);
      setError(null);
      props.navigation.navigate('App');
    } catch(err) {
      console.log('updatePassword -> err', err);
      setError(err.message);
    }
  };

Expected behavior According to the docs:

Screen Shot 2019-06-13 at 6 42 32 AM

Using promises has the same issue, no access to the user because it throws an error.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
haverchuckcommented, Jun 13, 2019

@appjitsu You say:

Calling Auth.signIn throws an error “PasswordResetRequiredException”. The problem is that Auth.sendCustomChallengeAnswer requires the user object from signin.

If you are receiving a ‘PasswordResetRequiredException’ error, can’t you transition to the reset password component from within the catch block, but if you don’t receive an error transition to a sendCustomChallengeResponse component (assuming you have one) when the signIn response doesn’t throw an error? Try looking at the React authenticator logic.

Apologies if I’ve misunderstood your issue. If this response doesn’t help please clarify the problem.

0reactions
github-actions[bot]commented, Jun 12, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication Security: Password Reset Best Practices and ...
Pitfalls in a 'Forgot Password' Flow and Best Practices to Address It · ✕ Allowing Login ID Guesses · ✓ Give 'Reset Password'...
Read more >
Force Password Reset on initial login custom policy not working
Force Password change works only with Sign-in policy. It does not work with SignInSignUp policy. Have a look at the discussion here.
Read more >
Set up a password reset flow - Azure AD B2C - Microsoft Learn
For Identity providers, enable Reset password using username or Reset password using email address. Under Multifactor authentication, if you ...
Read more >
Force.com Site - Custom Forgot Password page not working ...
We have a Force.com site where we enabled login options and for the forgot Password link on the login page settings we have...
Read more >
Forgot Password - OWASP Cheat Sheet Series
In order to implement a proper user management system, systems integrate a Forgot Password service that allows the user to request a password...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found