[英]Check if a user already exists with AWS Amplify Android?
Is there way to check if a user exists, before trying to sign them up?在尝试注册用户之前,有没有办法检查用户是否存在? When I try to signing up an existing username, it causes an error.当我尝试注册现有用户名时,会导致错误。 Here's the current method I'm using, but it doesn't work.这是我正在使用的当前方法,但它不起作用。
private View.OnClickListener registerClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
cognitoUser = userPool.getUser(Username.getText().toString());
if (cognitoUser.getUserId().isEmpty()) {
Amplify.Auth.signUp(
Username.getText().toString(),
Password.getText().toString(),
AuthSignUpOptions.builder()
.userAttribute(AuthUserAttributeKey.email(), Email.getText().toString())
.build(),
result -> Log.i("AuthQuickStart", "Result: " + result.toString()),
error -> Log.e("AuthQuickStart", "Sign up failed", error)
);
} else {
Toast.makeText(getApplicationContext(), "Username is taken", Toast.LENGTH_SHORT)
.show();
Username.requestFocus();
}
}
};
To be able to use the GetUser
API call you need a valid AccessToken
.为了能够使用GetUser
API 调用,您需要一个有效的AccessToken
。 And for that you already need to be authenticated.为此,您已经需要进行身份验证。 So you can't use it this way.所以你不能这样使用它。
Also, Cognito currently does not offer a simple way of checking if user already exists.此外,Cognito 目前不提供检查用户是否已存在的简单方法。
So your only option is to rely on exceptions thrown by the sign up action.因此,您唯一的选择是依赖注册操作引发的异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.