0

I am using aws cognito for authentication, I am finding difficulty in checking if the user has logged in or logged out. How to check in aws cognito if the user has logged in or he has logged out? Is there any method likeuserPool.currentUser.isLoggedIn()in android for checking if the user is logged in?

divyanshu dhawan
  • 109
  • 3
  • 13

2 Answers2

1

The docs for the AWSMobileClient, found here, which is part of the AWS Amplify SDK for Android, includes state tracking of logged-in users with the isSignedIn method.

hephalump
  • 5,860
  • 1
  • 22
  • 23
0

If your user did sign in once, aws mobile sdk will remember the username and save tokens so that next calls to sign in will immediatelly return "success".

You can add a call to userPool.getCurrentUser().getSession(authenticationHandler); when your app starts, and, if the credentials are valid and tokens did not expire, your onSuccess method will be called immediately, without making any internet call.

Then your application can set the user state to "signed in" and it should remember the state.

If getSession does not call success, on any of the other methods like onFailure or even on getAuthenticationDetails, you could show the login dialog right then, if you need the user logged in at that moment. Or you can decide to not show the dialog, and just set your internal user state to "not signed in".