I have problem with keeping user logged in to AWS Cognito in my android app. This is the code which checks that:
CognitoUser user = AppHelper.getPool().getCurrentUser();
username = user.getUserId();
if(username != null) {
AppHelper.setUser(username);
inUsername.setText(user.getUserId());
user.getSessionInBackground(authenticationHandler);
}
The problem is that sometimes (I guess after some time) the app forgets the user and that code:
user.getUserId();
Returns null. However that is never null:
AppHelper.getPool().getCurrentUser();
My code basis on the code from the sample app so I cannot understand why it doesn't work. I though that there might be a problem with Cognito pool, so I changed in devices options to always remember user device, but the issue didn't disappear.
Hi Grzegorz Brzęczyszczykiewicz,
user.getUserId();
will always return the userid, if the referenced CognitoUser object was created with CognitoUser user = AppHelper.getPool().getCurrentUser();
after a user had previously successfully signed-in.
An explanation for the behavior you are seeing could be that the user
was changed to reference a CognitoUser object which was not set to any user. This can happen when CognitoUser user = AppHelper.getPool().getCurrentUser();
is executed after clearing app data on the Android device.
Can you give provide any more details about your app, to better understand the issue? When the app executes user.getSessionInBackground(authenticationHandler);
, are you able to successfully sign-in?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.