IndominusByte / fastapi-jwt-auth

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)
http://indominusbyte.github.io/fastapi-jwt-auth/
MIT License
627 stars 143 forks source link

How to trigger token refresh? #102

Open WiraDKP opened 6 months ago

WiraDKP commented 6 months ago

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 🙏

salmansyyd commented 4 months ago

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.