Skip to content Skip to sidebar Skip to footer

How To Check Existing User In Cognito - Android?

so i have aws cognito set up in android. And i want to perform a check to see when the user enters a username, that that username doesn't already exist in my cognito pool. Currentl

Solution 1:

If you try signing in with a username that doesn't exist, you will get a UserNotFoundException exception.


Solution 2:

ListUsers now makes this much easier.

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html

Here is a simple .NET example:

        Dim userRequest = New ListUsersRequest With {
                .UserPoolId = userPoolId,
                .Filter = "username = JohnDoe"
            }
        Dim response = client.ListUsers(userRequest)
        If response.Users.Count < 1 Then
            Return False
        End If
        Return True

Solution 3:

This will help

catch(Exception exception){
    if(exception.getMessage().contains("UserNotFoundException")){
        ...
    }
}

Solution 4:

The answer to my question is:

        SignUpHandler signupCallback = new SignUpHandler() {

            @Override
            public void onSuccess(CognitoUser cognitoUser, boolean userConfirmed, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails)
            {
                Log.d(COGNITO_REGISTER, "sign up succeeded!");

            }
            @Override
            public void onFailure(Exception exception)
            {
                Log.d(COGNITO_REGISTER, "sign up failed!");
                Log.d(COGNITO_REGISTER, exception.getMessage());

                // Sign-up failed, check exception for the cause
            }
        };
        userPool.signUpInBackground(username_ET.getText().toString(), password_ET.getText().toString(), userAttributes, null, signupCallback);

Post a Comment for "How To Check Existing User In Cognito - Android?"