amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

reporting UserNotFoundException error #168

Open KypMon opened 5 years ago

KypMon commented 5 years ago

I am trying to write integrated testing on my current project when I try to authenticate a user with the amazon-cognito-auth-js library, and then I got an error of

code: {"UserNotFoundException", message: 'User does not exist.'}

for the code I used below, it is actually the example 4 of https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html.

It is hard for me to find out the reason, but I am pretty sure all the user information are correct, wondering if some error in the configuration. Also, the project I am working on using a 3rd party auth (oneLogin), is there any possibility happens on that side's configuration. But I am not sure since the actual auth system in the real application works pretty fine.

    async login(username, password) {
        const authenticationData = {
            Username: username,
            Password: password
        };
        var authenticationDetails = new AuthenticationDetails(authenticationData);

        var poolData = {
            UserPoolId: poolid,
            ClientId: clientid
        };

        var userPool = new CognitoUserPool(poolData);

        var userData = {
            Username: username,
            Pool: userPool
        };

        var cognitoUser = new CognitoUser(userData);

        cognitoUser.authenticateUser(authenticationDetails, {  // error here
            onSuccess: function (result) {
                //...
            },
            onFailure: function(err) {
                //...
            }
        });
    }

Appreciated for the help of any kinds.


Update: After I try the fake userpool data, the error is still 'user not found", probably I need to enable some specific setting to use this?