Skip to content

feat: proactive silent token refresh via setInterval polling#75

Merged
eugenioenko merged 14 commits into
mainfrom
feat/proactive-auto-refresh
May 9, 2026
Merged

feat: proactive silent token refresh via setInterval polling#75
eugenioenko merged 14 commits into
mainfrom
feat/proactive-auto-refresh

Conversation

@eugenioenko
Copy link
Copy Markdown
Owner

Summary

  • Adds setInterval-based proactive token refresh to OidcClient that renews the access token before it expires
  • Two new config options: autoRefresh (default true) and autoRefreshInterval in seconds (default 10)
  • On failure, polling stops to avoid hammering the token endpoint; a successful manual refresh or new login restarts it
  • Updated token-refresh guide with proactive refresh documentation

Test plan

  • Auto-refresh triggers when token is near expiry
  • No refresh when token is not near expiry
  • Disabled with autoRefresh: false
  • Stops on logout
  • Stops on destroy
  • Stops polling after a failed refresh (no endpoint hammering)
  • Restarts after failed auto-refresh followed by successful manual refresh

Closes #74

🤖 Generated with Claude Code

eugenioenko and others added 14 commits May 8, 2026 11:00
Adds interval-based polling to OidcClient that refreshes the access token
before it expires, so consumers always have a valid token without needing
401 interceptors or RequireAuth re-mount flashes.

Closes #74

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adapters previously typed the config prop as OidcConfig (from core),
which excluded client-specific options like autoRefresh and
autoRefreshInterval. Changed to OidcClientConfig from oidc-js so
TypeScript accepts the full config surface. Bumped all packages to 1.1.2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fetchProfile is already part of OidcClientConfig. Adapters no longer
need to extract it as a separate prop and merge it — they pass config
directly to OidcClient, which defaults fetchProfile to true internally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add autoRefreshInterval localStorage toggle to all 8 e2e apps and a new
Proactive Auto-Refresh test that sets a 1s polling interval, simulates
token expiry, and verifies the interval fires a refresh without user
interaction. Rename login.spec.ts to oidc.spec.ts to reflect the
broader scope of the test suite.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The kasper app was still passing fetchProfile as a separate template
attribute, but the AuthProvider no longer reads it as a separate arg.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move fetchProfile into the module-level config constant instead of
spreading it inline in JSX/template. The inline spread created a new
object reference on every render, causing React/Preact's useEffect
(which depends on [config]) to re-fire, destroying the authenticated
client and creating a new unauthenticated one in a loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@eugenioenko eugenioenko merged commit 393b47a into main May 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: proactive silent token refresh via setInterval polling

1 participant