Authenticated Polling in Lit Clients
Use a shared auth service plus a reusable poller utility.
Auth Service Responsibilities
- Store JWT in
localStorage. - Provide
getAuthHeaders(). - Auto-clear token on 401.
- Redirect to
/login?return=<current path>when unauthorized.
Poller Utility Contract
createPoller({
getEndpoint,
intervalMs,
terminalStates,
onStatus,
onComplete,
onError
});
Polling Behavior
- Immediate first poll on start.
- Interval-based polling until terminal state.
- Stops automatically on completion or error.
- Handles 401 centrally via auth redirect.
Cleanup Rule
Always call poller.stop() in component disconnect lifecycle to avoid orphan intervals.