Amplify-js: "Local storage is missing an ID Token, Please authenticate" error while changing password Cognito AWS

Created on 3 Aug 2018  路  12Comments  路  Source: aws-amplify/amplify-js

I am building an application. In that Sign up, Signin and other operations are working fine. But, when I try to change password using following code, it says

"Local storage is missing an ID Token, Please authenticate"

Code is:

changePassword(mail: any) {
    var that = this;
    var userPool = new CognitoUserPool(this.poolData);
    var userData: any = {
        Username: mail,
        Pool: userPool
    };
    var cognitoUser = new CognitoUser(userData);
    // To get the session
    cognitoUser.getSession(function (err, session) {
        if (err) {
            alert(err);
            return;
        }
        var userPool = new CognitoUserPool(that.poolData);
        var userData: any = {
            Username: mail,
            Pool: userPool
        };
        var cognitoUser = new CognitoUser(userData);
        var oldp = prompt('Please input old password ', '');
        var newp = prompt('Please input new password ', '');
        cognitoUser.changePassword(oldp, newp, function (err, result) {
            if (err) {
                alert(err.message || JSON.stringify(err));
                return;
            }
            alert("Password successfully changed...");
        });
    });
}

I am not sure what is wrong in this. Please help me solve this.

Thank you...

Auth documentation pending-close-response-required

Most helpful comment

@saikumar-madana maybe it's too late but cognitoUser.changePassword or cognitoUser.changePassword will throw error when the user is not authenticated.

@dguisinger if you created a user from the cognito console, you need to call Auth.completeNewPassword(cognitoUser, password, required_attrs) to submit the new password and finish the sign in process.

All 12 comments

Same issue in Auth.changePassword()

I think the issue is due to how the Cognito is configured.

Ie: Cognito Identity must be token based otherwise it wont work....

Well i solved something due to that.. and it finally worked..

very odd...it says in the [Authentication Guide(https://aws-amplify.github.io/amplify-js/media/authentication_guide) that local storage is optional yet if Amplify is NOT providing its own storage, then it appears that this is actually required?

What was the solution here?

Any solutions to this?
I'm having the same issue while calling Auth().userAttribute()

Saturday I opened issue #1853 regarding the issue I was having with userAttribute(), also seems to apply to change password now that I have tried to dig into it with a debugger, just like this ticket. In my case, the user was a new user created from the AWS console and needed a change password upon login. It appears that the code doesn't put that user into the local storage since they aren't logged in... ok, makes some sense, I can buy that... but since it doesn't let me change the password either, I can't test that hypothesis.

Would be nice if we got some feedback from Amazon, I'm dead in the water until I get this resolved.

@saikumar-madana maybe it's too late but cognitoUser.changePassword or cognitoUser.changePassword will throw error when the user is not authenticated.

@dguisinger if you created a user from the cognito console, you need to call Auth.completeNewPassword(cognitoUser, password, required_attrs) to submit the new password and finish the sign in process.

Wait, that error message actually does mean the user must be authenticated and that the call requires an authenticated user?

Can we get a better error message? The internet is full of people asking what the heck this error message means, I can't imagine how many others are getting this message and have no idea what it means.

@dguisinger thanks for the feedback, we will try to improve those error messages in the future.

I do agree, the messages should be explicit. However adding a section regarding this issue within the AWS Amplify authentication guide would be a better approach.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Was this page helpful?
0 / 5 - 0 ratings