amazon-cognitoaws-sdk-js-v3

Users unable to authenticate with their email and password with AWS Cognito


I have a test user who has confirmed their email with AWS Cognito. I get a NotAuthorizedException: Incorrect username or password. when I attempt to initiate auth with them using their email and password. Currently, I can only authenticate users with their username.

Here is how I am initiating auth with a user. I supply their email in the USERNAME field.

public initiateAuth(args: WithAuthFlowType<InitiateAuth>): Promise<InitiateAuthCommandOutput> {
    //https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html

    return new CognitoIdentityProviderClient({region: "us-east-1"}).send(
        new InitiateAuthCommand({ //https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cognito-identity-provider/classes/initiateauthcommand.html
            ClientId: "<some_client_id>",
            AuthFlow: AuthFlowType.USER_PASSWORD_AUTH,
            AuthParameters: {
                USERNAME: "foo@bar.com",
                PASSWORD: "1234...",
            },
        })
    );
}

I believe I configured AWS Cognito well. In the console it shows users can sign in with their email. How can I let my users authenticate with their email and password?

AWS Cognito Console


Solution

  • Discovered that this was user error. User had a period in their email like.

    f.bar@baz.com

    The user was attempting to sign in as

    fbar@baz.com

    Which is why they were unable to sign in.