'change password not working amplify amazon

i am trying to implement a simple password change after user gets invitation by email.

my code for changing password is from documentation:

https://docs.amplify.aws/lib/auth/manageusers/q/platform/js/

import { Auth } from 'aws-amplify';

Auth.currentAuthenticatedUser()
    .then(user => {
        return Auth.changePassword(user, 'oldPassword', 'newPassword');
    })
    .then(data => console.log(data))
    .catch(err => console.log(err));

it is showing an error



NotAuthorizedException: Incorrect username or password.

which is not true, anyone had similar issue?,

I tried different solutions for this pasword change but seems I can get my head around it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source