Problem
Users are unexpectedly logged out of the HAPI web UI after a period of inactivity. Both I and another user have experienced this — we're logged in, switch to another tab or step away, and when we come back the session is gone.
Root cause
The JWT token issued at login has a hardcoded 15-minute expiration (hub/src/web/routes/auth.ts:74, hub/src/web/routes/bind.ts:54):
.setExpirationTime('15m')
The frontend does have an auto-refresh mechanism (web/src/hooks/useAuth.ts:254) that schedules a refresh 60 seconds before expiry. However, when the browser tab is in the background, the browser throttles JavaScript timers, so the scheduled refresh may not execute in time. When the user returns:
- Token is already expired
- Emergency refresh attempt may fail (network hiccup, race condition)
- Frontend clears auth state → user sees login screen
Suggestion
Extend the JWT expiration to a longer duration (e.g. 7 days). HAPI is a self-hosted personal tool, not a public SaaS, so the security trade-off seems acceptable. The access token in localStorage is already long-lived — the short JWT lifetime doesn't add meaningful security since an attacker with access to the browser already has the access token.
Alternatively, the refresh mechanism could be made more robust (retry on failure instead of immediately clearing auth state).
Relevant code
hub/src/web/routes/auth.ts:74 — setExpirationTime('15m')
hub/src/web/routes/bind.ts:54 — setExpirationTime('15m')
web/src/hooks/useAuth.ts:110-118 — clears auth on refresh failure when token is expired
web/src/hooks/useAuth.ts:225-262 — auto-refresh scheduler
Problem
Users are unexpectedly logged out of the HAPI web UI after a period of inactivity. Both I and another user have experienced this — we're logged in, switch to another tab or step away, and when we come back the session is gone.
Root cause
The JWT token issued at login has a hardcoded 15-minute expiration (
hub/src/web/routes/auth.ts:74,hub/src/web/routes/bind.ts:54):The frontend does have an auto-refresh mechanism (
web/src/hooks/useAuth.ts:254) that schedules a refresh 60 seconds before expiry. However, when the browser tab is in the background, the browser throttles JavaScript timers, so the scheduled refresh may not execute in time. When the user returns:Suggestion
Extend the JWT expiration to a longer duration (e.g. 7 days). HAPI is a self-hosted personal tool, not a public SaaS, so the security trade-off seems acceptable. The access token in localStorage is already long-lived — the short JWT lifetime doesn't add meaningful security since an attacker with access to the browser already has the access token.
Alternatively, the refresh mechanism could be made more robust (retry on failure instead of immediately clearing auth state).
Relevant code
hub/src/web/routes/auth.ts:74—setExpirationTime('15m')hub/src/web/routes/bind.ts:54—setExpirationTime('15m')web/src/hooks/useAuth.ts:110-118— clears auth on refresh failure when token is expiredweb/src/hooks/useAuth.ts:225-262— auto-refresh scheduler