I am new to Flutter and want to write an app to an existing backend. The backend - since it also provides the backend to a Vue.JS app - already handles JWT tokens. The issue which arises is how to hanle JWT tokens in Flutter correctly. The JWT timeout is around 15 minutes. I have already garned the web for minimal working examples. I saw examples with dio and fresh_auth. I would like the first one, however, I have no idea on how to periodically update the token. Thanks in advance.
Asked
Active
Viewed 128 times
0
-
Are you asking (1) how to get a new access token at all, or are you asking (2) how to do that periodically? The general answer to (2) is, you just do it opportunistically whenever you send your next authenticated request: if you've calculated that you need a new one, if you get 401'd, or simply on every request. – Noah Jul 25 '21 at 13:36
-
I was going for (2), I am new to Flutter and therefore am glad for every help received. – Peter Jul 27 '21 at 07:26
-
dio is the way forward. You can find a very good example of DIO handling the requests here on StackOverflow. Nonetheless, I would recommend using seperate endpoints for the Vue.JS part and the Flutter app, giving you more space to develop own mechanisms for your cell phone and maybe storing - depending on the user base - the cell phone tokens in a Redis table, which can also take care of destroying old tokens after a specific time. – Peter Nov 10 '21 at 20:11