我正在尝试在我的 AWS Amplify Auth
应用中使用 Android
。注册和登录有效,现在我正在尝试获取已登录用户的用户属性,但 Amplify 在 Amplify.Auth.fetchUserAttributes()
函数中引发异常。
我的登录代码:
private void login(String email, String password) {
Amplify.Auth.signIn(
email,
password,
result -> {
if (result.isSignInComplete()) {
Log.i(TAG, "Sign in succeeded");
Log.i(TAG, "going to fetch User attributes");
Amplify.Auth.fetchUserAttributes(
attributes -> Log.i("AuthDemo", "User attributes = " + attributes.toString()),
error -> Log.e("AuthDemo", "Failed to fetch user attributes.", error)
);
Log.i(TAG, "end of fetching User attributes");
} else {
Log.i(TAG, "Sign in not complete");
}
},
error -> Log.e(TAG, error.toString())
);
}
日志:
I/LoginActivity: Sign in succeeded
W/InternalCallback: Library attempted to call user callback twice, expected only once
I/LoginActivity: going to fetch User attributes
D/AWSMobileClient: Inspecting user state details
D/AWSMobileClient: waitForSignIn: userState:SIGNED_OUT
E/AuthDemo: Failed to fetch user attributes.
AuthException{message=Failed to fetch user attributes, cause=java.lang.Exception: Operation requires a signed-in state, recoverySuggestion=Ensure that you are logged in and online}
at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin$15.onError(AWSCognitoAuthPlugin.java:736)
....
Caused by: java.lang.Exception: Operation requires a signed-in state
...
它告诉我用户状态是:SIGNED_OUT,但我在成功登录方法中调用它,那么为什么用户退出了?