Skip to content

feat(auth): implement proactive SIWE session expiry warning banner (#226)#321

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
TheDEV111:feat/226-siwe-proactive-session-warning
Jul 25, 2026
Merged

feat(auth): implement proactive SIWE session expiry warning banner (#226)#321
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
TheDEV111:feat/226-siwe-proactive-session-warning

Conversation

@TheDEV111

Copy link
Copy Markdown
Contributor

Summary

Fixes #226

This PR introduces a proactive, dismissible warning banner for SIWE administrative sessions before the access token expires. Previously, session expiration only triggered an error banner after a failed mutation request (401), causing administrators to lose in-progress work (such as active edits in the Policy Editor).

Now, administrators are notified ahead of time with a live countdown and can extend their session with a single click before any requests fail.


Changes Included

  • Proactive Warning Helpers (lib/session.ts):
    • Defined DEFAULT_WARNING_THRESHOLD_SECONDS (120s / 2m).
    • Added getRemainingSessionSeconds(), isSessionExpiringSoon(), and formatTimeRemaining() helpers.
  • Configurability (lib/config.ts):
    • Added warningThresholdSeconds to SiweConfig, populated via environment variables (NEXT_PUBLIC_SIWE_WARNING_MINUTES or NEXT_PUBLIC_SIWE_WARNING_SECONDS), defaulting to 2 minutes.
  • Context & Provider Wiring (lib/wallet/siwe-context.ts & lib/wallet/providers.tsx):
    • Exposed isExpiring and warningThresholdSeconds through SiweAuthContext.
    • Unified SiweAuthContext instance between definition module and provider tree.
  • UI & Accessibility (components/admin-guard.tsx):
    • Rendered a styled, accessible (role="status", aria-live="polite", aria-label="Extend your signed-in session") warning banner when isExpiring is active.
    • Included a live countdown timer ({currentSeconds}s), an Extend Session action button, and a Dismiss option.
    • Automatically clears the banner upon successful re-authentication.
    • Non-admin and unauthenticated users do not see the warning banner.
  • Testing (test/siwe-proactive-warning.test.ts):
    • Added unit test suite validating warning helper functions, countdown logic, threshold detection, and AdminGuard render behavior.

Verification

  • Executed npm run test: 497 tests across 93 suites passed with 0 failures.
  • Tested re-auth flow and dismissal interactions.

@Lakes41
Lakes41 merged commit 25e6ac5 into Adamantine-guild:main Jul 25, 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.

Show a SIWE session expiry countdown and pre-expiry warning

2 participants