Detect user’s JWT expired #1705

Closed
opened 2020-02-18 05:53:49 +00:00 by jtojnar · 4 comments
Contributor

When JWT expires, the front-end should show a login form instead of throwing a bunch of errors in notifications.

Though we should make sure that data is not discarded, for example when JWT expires during the time user is editing a task description.

When JWT expires, the front-end should show a login form instead of throwing a bunch of errors in notifications. Though we should make sure that data is not discarded, for example when JWT expires during the time user is editing a task description.
Owner

The second part sounds slightly harder to solve.

At best, the jwt token would be renewed in reccurring intervals, in the best case we could do this with some support of the service worker

The second part sounds slightly harder to solve. At best, the jwt token would be renewed in reccurring intervals, in the best case we could do this with [some support of the service worker](https://stackoverflow.com/a/44783400/10924593)

The main reason the JWT expires is that the user leaves the app or tab to do something else, no? So if it's possible with the workers or some other browser hook, on resume of the app/tab session, do a quick check to see if the JWT is valid, and redirect to login if not.

I'm not a front-end engineer, but that should generally prevent the user from having a chance to enter in data in a form that might be lost, no?

The main reason the JWT expires is that the user leaves the app or tab to do something else, no? So if it's possible with the workers or some other browser hook, on resume of the app/tab session, do a quick check to see if the JWT is valid, and redirect to login if not. I'm not a front-end engineer, but that should generally prevent the user from having a chance to enter in data in a form that might be lost, no?
Owner

Checking (and maybe renewing) if a tab becomes active sounds like a good idea. My solution so far was to simply try to renew the token every few minutes, but that seems to have issues.

I've pushed an update to attept renewing the token every time the browser tab gains focus again in dc29604f94. We'll see how this works in practice.

Checking (and maybe renewing) if a tab becomes active sounds like a good idea. My solution so far was to simply try to renew the token every few minutes, but that seems to have issues. I've pushed an update to attept renewing the token every time the browser tab gains focus again in https://kolaente.dev/vikunja/frontend/commit/dc29604f94634e20de2b14481cb6ddf1b46d3fcc. We'll see how this works in practice.
Owner

I havn't noticed any issues with renewing the token every time the window gains focus so far, therefore I'll close this issue. The error handling was also improved so that you'll just get redirected to the login page if you visit Vikunja after a token expired - no confusing error message.

Feel free to reopen if you encounter any issues.

I havn't noticed any issues with renewing the token every time the window gains focus so far, therefore I'll close this issue. The error handling was also improved so that you'll just get redirected to the login page if you visit Vikunja after a token expired - no confusing error message. Feel free to reopen if you encounter any issues.
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: vikunja/vikunja#1705
No description provided.