amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

What should you do when the refresh token expires after 30 days? #183

Open kocur4d opened 5 years ago

kocur4d commented 5 years ago

The refresh token expires after 30 days, and the docs say

If the refresh token is expired, your app user must reauthenticate by signing in again to your user pool.

But how do I know in advance when this should happen?

I don't want my users to be kicked out in a middle of a day and ask them to reauthenticate because the Refresh token decided to expire now.

I would ideally like to check, every time when the page is loaded, if refresh token is getting close to expiring and then log user out and ask him to login again, but Refresh token don't have any data assigned to it indicating it expiry date.

How do you guys deal with a situation of refresh token getting expired?

ronkot commented 4 years ago

The refresh token expiry time is configurable option. I've set it to maximum (10 years 😅). Basically long refresh token validity time is the only way to keep users logged in for long time.

If you want to check expiry time of an issued refresh token, I think you could decode the token (it's a JWT) and read the exp claim which should contain expiry time in unix time.