amplify-js: Auth.changePassword TypeError: user.getSession is not a function
Describe the bug
When upgrading library to 1.1.10 login and logout seems to work, however changing password shows a Possible Unhandled Promise Rejection
To Reproduce Steps to reproduce the behavior:
Auth.currentAuthenticatedUser()
.then((user) => {
return Auth.changePassword(user, oldPassword, newPassword)
})
.then((data) => {
console.log('changePassword:', data)
this.props.navigation.navigate('Profile')
})
.catch((err) => {
console.log(err)
})
Generates:
Possible Unhandled Promise Rejection (id: 0):
TypeError: user.getSession is not a function
TypeError: user.getSession is not a function
at blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:103866:22
at tryCallTwo (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:8841:7)
at doResolve (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:9005:15)
at new Promise (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:8864:5)
at AuthClass.userSession (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:103864:20)
at blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:103676:23
at tryCallTwo (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:8841:7)
at doResolve (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:9005:15)
at new Promise (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:8864:5)
at AuthClass.userAttributes (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:103675:20)
Expected behavior I expect to change password per the documentation and not have any errors.
Smartphone (please complete the following information):
- Device: iPhoneX Simulator
Additional context
- “react”: “^16.3.1”,
- “react-native”: “^0.55.4”,
- “aws-amplify”: “^1.1.10”
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 16 (5 by maintainers)
@strykerCrew we tried to reproduce your issue today but were unsuccessful. If you could would you be able to send us a gist or link to an example of your application code and the lifecycle of calling it in the app? Also, we have a Gitter channel https://gitter.im/AWS-Amplify/Lobby which our team could help you during the day tomorrow that might help for troubleshooting.
In the meantime, some thoughts: It could be that
Auth.changePasswordis being invoked out of band because the stack trace above showsAuthClass.userAttributes (blob:file:///6134849c-a9bf-4aff-8573-9a29532aed54:103675:20). Additionally, theuserobject you showed does not appear to be a valid Cognito user object.We put together a sample below from scratch showing the API functionality as well as the
userobject that you should be seeing.The below configuration file is automatically generated with the Amplify CLI when you run
amplify add author you can manually create an Identity Pool and User Pool. Note that theaws_user_pools_web_client_idis an App client that does NOT have a client secret:The React Native application below was created with
react-native initand demonstrates registering a user with a confirmation code, signing in with that user, and finally callingAuth.changePassword()in the application using the above configuration file. I hardcoded some variables such as the username, email, and passwords for demonstrative purposes:Here is the
package.jsonwhich is slightly different to your versions but the major version match:When the above application code runs and you pass through the registration and sign-in flows, you will see a button that says “Change password” which upon clicking logs the
userobject. This is what I see when running this:@strykerCrew We suspect that you might be calling
federatedSignInsomewhere in your code and this is not needed in this case, because the library takes care of getting the credentials when you have an Identity Pool configured with a User Pool.Could you confirm that’s the case? If so, this would explain the problem; as roughly speaking, the
federatedSignInis an independent process which caches it’s own user object which makes sense when running it independently. However if you use it along with the standard Auth methods that are already performing federation, problems occur.If this is the case could you let us know why you might have thought that calling this separately in your code was necessary? We haven’t seen customers do this before.