fastapi-jwt-auth icon indicating copy to clipboard operation
fastapi-jwt-auth copied to clipboard

How to trigger token refresh?

Open WiraDKP opened this issue 1 year ago • 1 comments

tldr; What is the best practice to refresh the token or how would you recommend triggering it?

The example has provided a refresh endpoint (/refresh). When the access token has expired, it seems to raise AuthJWTException. Do we capture the exception and redirect to the /refresh endpoint? How to do it?

Thank you in advance 🙏

WiraDKP avatar Dec 22 '23 05:12 WiraDKP

I had the same question but then after thinking a little the /refresh logic works in the frontend when the auth_token expires back-end returns an exception that is handled on the front-end, it should send another request to the /refresh endpoint this time with the refresh token and it will return the auth_token and this cycle will continue until the refresh_token is expired.

When the refresh_token is expired the /refresh endpoint will return an exception and this is when the front-end will redirect the user to the login page, and another cycle will start.

salmansyyd avatar Mar 03 '24 07:03 salmansyyd