New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user.completeNewPasswordChallenge is not a function #1715
Comments
@goatandsheep hi can you confirm that the |
More detailsupon FixI whitelisted the password change page to not be auth protected and put the value into my store SuggestionProvide a way to obtain the user object when the user is not yet confirmed other than signIn. Even if it's located in the error message. I don't even know if it's cached. |
@goatandsheep When you get resolved from |
@powerful23 right! However, the user object that comes back from |
Same error.. CognitoUser {username: "fooUser", pool: CognitoUserPool, Session: "ysigtMhHzzzWchNgzYZnvfQg2cbWEjKFr6wR1lf1VA…Gl5Ua9XZphoX21tzCchHYxKzzdl_9hbihiQTzfHEy8_nrzs", client: Client, signInUserSession: null, …} Codeaws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].signIn(userNameField.value, passwordField.value)
|
you're missing a lot in your workflow. Here let me help you out: aws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].signIn(userNameField.value, passwordField.value)
.then(user => {
console.log(user);
MessagesDiv.innerHTML = "Sign in success";
if (user.challengeName === "SMS_MFA" || user.challengeName === "SOFTWARE_TOKEN_MFA") {
aws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].confirmSignUp(/* TODO */)
} else if(user.challengeName === "NEW_PASSWORD_REQUIRED"){
aws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].completeNewPassword( VerifyUser.value, 'NewPassword2018')
.then(() => {
MessagesDiv.innerHTML = "Sign in success. Password updated";
console.log('Password updated');
})
.catch(e => {
MessagesDiv.innerHTML = "failed with error" + e;
console.log('failed with error', e);
});
} else if (typeof user.challengeName !== 'undefined') {
console.error(user.challengeName)
}
function checkUser(user) {
aws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].verifiedContact(user)
.then((data) => {
console.log("verification result", data);
if (Object.keys(data.verified).length > 0) {
console.log("Successful login")
} else {
aws_amplify__WEBPACK_IMPORTED_MODULE_0__["Auth"].verifyContact(/* TODO */)
}
}
}
checkUser(user) |
Thank you for the help. I have few additional questions. 1. I am stepping through the code and see that the user.challengeName === "NEW_PASSWORD_REQUIRED" is true. The user status in cognito is FORCE_CHANGE_PASSWORD. So, the completeNewPassword is called but returns error *TypeError: user.completeNewPasswordChallenge is not a function at eval *. Although, the workflow steps you mention will have to be included in the production code, I have made MFA option turned off in the user pool configuration to keep things simple. I will try the code you have posted, turn MFA on and see if it resolves the error. I appreciate your help. |
How are you calling
|
Thank you. Your response helped in identifying my mistake. The user object passed to Auth.completeNewPassword was different from the one returned by signin method so it was failing. After changing to use the object returned by signin it works correctly. Confirmed in cognito console that the status of user does change correctly. |
Anyone can confirm that the user object returned from signIn can be stored in the session storage via JSON.parse()? |
I tried this (long story above - sessionstorage stores the same format as localstorage) and the object wasn't recognized properly. It needs to be a CognitoUser object. You're going to have to figure out how to pass it directly or put it in a 3rd party store like Redux or even Amplify Cache |
Thanks mate. I finally use the BehaviourSubject to store the user (this project is based on Angular). In case the user refreshed the page then I'll take it as session expired and redirect the user to the login page. Not perfect, but should be able to satisfy the PO |
this happened yesterday since we were using Immutable in redux reducers, which created a clone of the user object. If you are doing the same, please be aware and pass the user object directly. |
So this problem troubled me for some time. Amplify Cache didn't seem to work and caching username and password is a bad idea, however my work around was just include the username and password in the Require-New-Password form, so I have 4 inputs instead of just newPassword & confirmPassword which now is username, oldPassword, newPassword, and confirmPassword. Good luck! |
You can simply use the predefined amplify method like below. |
how does this solve "TypeError: user.completeNewPasswordChallenge is not a function"?? |
Would you please provide the working example for the rest of us? |
@mikeRChambers610 you have to pass the object returned by Here's an example using React: https://gist.github.com/davekiss/9af08fde4ce2d40e306a35028583d6e5 |
I think it should be a method to create a |
Here is some manual parsing to create const pool = new CognitoUserPool({
UserPoolId: cognitoObject.pool.userPoolId,
ClientId: cognitoObject.pool.clientId,
endpoint: cognitoObject.client.endpoint,
Storage: window.localStorage,
AdvancedSecurityDataCollectionFlag: cognitoObject.advancedSecurityDataCollectionFlag,
})
const cognitoUser = new CognitoUser({
Username: cognitoObject.username,
Pool: pool,
Storage: window.localStorage,
})
cognitoUser.Session = cognitoObject.Session
await Auth.completeNewPassword(cognitoUser, newPassword, cognitoObject.challengeParams) |
yes, it would throw an error because the object is no longer a cognitoUserObject since it has been stringified and parsed. What I did was to save the cognitoUserObject from sign-in to redux store and collect it back in the component where required. |
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 |
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Auth.completeNewPassword(userFromLoginAttempt, newPassword, requiredAttributes)
user.completeNewPasswordChallenge is not a function
Expected behavior
Password is changed and the user can login
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.
The text was updated successfully, but these errors were encountered: