amplify-js: user.completeNewPasswordChallenge is not a function
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
- Use flat aws-exports.js structure
- Set Cognito up such that Only Admin creates accounts
- Use Amplify but not mobile hub
- Create an account
- try to change the temporary password using
Auth.completeNewPassword(userFromLoginAttempt, newPassword, requiredAttributes) - Responds with
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):
- OS: MacOS
- Browser: Chrome
- Version: 1.0.0
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = ‘DEBUG’; in your app.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (2 by maintainers)
You can simply use the predefined amplify method like below.
const currentUser = await Auth.currentAuthenticatedUser();@goatandsheep When you get resolved from
Auth.signIn()with that user object, you are not actually signed in because you need to complete the new password. So at that momentAuth.currentSessionandAuth.currentAuthenticatedUserwon’t work because you are not signed in. You need to directly use that user object returned fromAuth.signIn()to help you finish the login process.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.
@goatandsheep hi can you confirm that the
userFromLoginAttemptobject should be aCognitoUserobject?I think it should be a method to create a
CognitoUserinstance from the returned object after stringify it and parse it again!Anyone can confirm that the user object returned from signIn can be stored in the session storage via JSON.parse()? When the user sign in at the first time, I redirect the page to the change password one, however when I use the stored user object to call the completeNewPassword() it always says the error as user.completeNewPasswordChallenge is not a function
Here is some manual parsing to create
CognitoUserinstance from the parsed object (cognitoObject):@mikeRChambers610 you have to pass the object returned by
Auth.signIn()instead of a username string. There isn’t anything in the session yet, so @nikhilknoldus suggestion will not workHere’s an example using React: https://gist.github.com/davekiss/9af08fde4ce2d40e306a35028583d6e5
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
you’re missing a lot in your workflow. Here let me help you out: