amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
986 stars 452 forks source link

authenticateuser method is not working. #629

Closed joe455 closed 6 years ago

joe455 commented 6 years ago

As part of my usercase I want to auto login the user into the app and show him the profile page.But which is not supported by cognito yet.So to tweak this case, I saved username and password on session storage and calling authenticating using authenticate user method once user confirmed. But for some reason it's not working. Could you somebody please help me.Below is my code. Auth(){ console.log("auth method");`

    let passkey = sessionStorage.getItem('pass1');
    let uname = sessionStorage.getItem('uname');
    console.log("password",passkey);

    //this.loginservice.authenticate(uname,passkey,null);
    let authenticationData = {
        Username : uname,
        Password : passkey,
    };
    console.log("authentication details",authenticationData);
    let authenticationDetails = new AuthenticationDetails(authenticationData);

    let userData = {
        Username: uname,
        Pool: this.cognitoUtil.getUserPool()
    };
    let cognitoUser = new CognitoUser(userData);
    console.log("cognitoUser",cognitoUser);
    let self = this;
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: (result) => {
            console.log("login sucuess",result);
        },
        newPasswordRequired: () => {

        },
        onFailure : (err) => {
            console.log("Login Failed",err.message);
        },
        mfaRequired: () => {
        }
});
    sessionStorage.clear();
}``

It's not showing error also :(

itrestian commented 6 years ago

You can try debugging with Chrome Developer Tools. You can see in the Network tab if any calls are made and if there is an error you can get a more descriptive message. Also try using non minified version of packages so that the variable names are kept.

joe455 commented 6 years ago

localstorage is not clearing on signout method.

itrestian commented 6 years ago

I don't really understand. You mean that is the issue?

joe455 commented 6 years ago

Sorry for confusing @itrestian .

I am able to authenticate but cognitoUser.signout() is not clearing cache/storage. Is this is a existed issue. ??

itrestian commented 6 years ago

I haven't seen this issue brought up before. signOut basically clears all the keys associated with the tokens retrieved from the service, it won't clear any of the data you might have written in your app, just the keys associated with the tokens.

joe455 commented 6 years ago

Got it!! Sorry for bothering @itrestian