所以我在android中设置了aws cognito。我想检查用户输入用户名的时间,该用户名在我的认知池中尚不存在。
目前我有这个:
cognitoUser = userPool.getUser(username_ET.getText().toString());
if(cognitoUser.getUserId().isEmpty())
{
//Great, this is a new user.
}
但是,cognitoUser只是设置为我放入的任何东西,它不会再次检查。
希望有人可以提供帮助!
答案 0 :(得分:1)
如果您尝试使用不存在的用户名登录,则会收到UserNotFoundException异常。
答案 1 :(得分:1)
ListUsers 现在使此操作变得更加容易。
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html
这是一个简单的.NET示例:
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
答案 2 :(得分:0)
这会有所帮助
catch(Exception exception){
if(exception.getMessage().contains("UserNotFoundException")){
...
}
}
答案 3 :(得分:-1)
我的问题的答案是:
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);