Handling forced password reset in custom authentication is broken
See original GitHub issueDescribe 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:
Using promises has the same issue, no access to the user because it throws an error.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@appjitsu You say:
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.
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.