Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

How to tell if ID & access tokens are expired? How do we refresh? #682

Open
ffxsam opened this issue Feb 10, 2018 · 2 comments
Open

How to tell if ID & access tokens are expired? How do we refresh? #682

ffxsam opened this issue Feb 10, 2018 · 2 comments

Comments

@ffxsam
Copy link

ffxsam commented Feb 10, 2018

(side note: I hope someone is working on the documentation for this repo.. a bunch of use cases in the README doesn't cut it)

I have an app where a user might be using it for well over an hour. During that time, the ID and access tokens expire, and errors are thrown when trying to access AWS services that expect the user to be authorized via Cognito.

How/when do we properly detect expiration? And how do we refresh those tokens seamlessly so the user doesn't experience any interruptions?

@ffxsam
Copy link
Author

ffxsam commented Feb 10, 2018

Aha. cognitoUser.refreshSession() is not documented.

https://github.com/aws/amazon-cognito-identity-js/blob/6059c168270f8cf6b5d786e0b9dddd74fb06aa62/src/CognitoUser.js#L1074-L1113

This is hacky, but I set up a 30-min timer to auto refresh the ID & access tokens. If there's a better way, I'm all ears.

@itrestian
Copy link
Contributor

You can basically wrap your calls in a call to getSession in which case the SDK always checks if the access token is valid and if not it uses the refresh token to retrieve a new access token.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants