#How to check if token is expired

7 messages ยท Page 1 of 1 (latest)

jagged frost
#

Hello ๐Ÿ‘‹ How can I check if the user jwt token is expired?
And how can I set the jwt token to expire by 30 mins rather than 60 mins as the default?

Context:
I've integrated amplify vue v6 into a vue 3 app. I'm wondering what's the best practice to check if the jwt token is expired.
At the moment I'm using fetchAuthSession function that automatically refreshes the token. Is there a way I can check against cognito if the token is expired without refreshing the token?

I want to avoid auto-refreshing the token and rather force the user to authenticate through sign-in. The only way I can think of doing this is to set a timeout variable (or check if its been 30 mins after sign-in), triggering auth.signOut, and routing the user to login screen.
Is there a better way of achieving this? ๐Ÿ‘€

Secondly, doesn't anyone have a link to cognito docs that show how to customise the token expiration? I see the default is 60 mins, but I want to set it to 30 mins.

viral hatch
#

๐Ÿ‘‹ are you using a gen1 or gen2 backend?

jagged frost
#

gen 1

viral hatch
#

you can use overrides to modify the validity of your access and refresh token, though Cognito will only allow 60m as the minimum for the refresh token. Once the access token expires the library will use the refresh token to request a new access token. Once that refresh token expires the library will throw and you can use that to redirect

#

are you looking to only allow sessions of 30m at a time?

jagged frost
#

Yeah 30min session.
I'm pretty sure I've hit the error when the refresh token is expired. But I don't understand fully how to control the behaviour.

viral hatch