Skip to content

Web UI auto-logout after ~15 minutes of inactivity #412

@hqhq1025

Description

@hqhq1025

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:

  1. Token is already expired
  2. Emergency refresh attempt may fail (network hiccup, race condition)
  3. 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:74setExpirationTime('15m')
  • hub/src/web/routes/bind.ts:54setExpirationTime('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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions