amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

Appropriate way to determine whether UI will be triggered?

Open craigatproperly opened this issue 7 years ago • 3 comments

When I use getSession() it could trigger UI or could exchange refresh tokens. I am trying to implement a UI that prompts for "Login" if there is no unexpired token and instead shows "Signout" if there is.

I can use the success callback whether or not it exchanges refresh tokens or it does the login, but, basically I would like to be able to predict if getSession is going to trigger a redirect.

Is there a recommended/appropriate way to do that check? I feel like I want something like hasSession = "hasIDToken || (hasRefreshToken && refreshToken.exp < now()) " or equivalent.

craigatproperly avatar May 01 '18 15:05 craigatproperly

+1

I call getSession to find out if the user is logged in or not. If they are not logged in, I don't want to redirect them immediately to the hosted UI. Is there a way to tell it to not auto-redirect or a different method to see if they are logged in or not?

dankantor avatar Jul 19 '18 21:07 dankantor

I don't know that it is part of the API contract, but, I found this utility function that performed a check similar to what I wanted. So I am using this for now. It appears to be working, but, I haven't systematically checked all the expiry and logout scenarios: https://github.com/aws/amazon-cognito-auth-js/blob/1ea0f1d9282201f31411ac87b8a96a244793c1f4/es/CognitoAuth.js#L831

craigatproperly avatar Jul 19 '18 21:07 craigatproperly

How exactly to use this please ? I want to check if user has logged in.. But before that the UI gets triggred and errors out .

chittasec avatar Mar 14 '19 11:03 chittasec