Skip to content

fix(auth): suppress session expiration warnings for visitors - #330

Merged
cxymds merged 1 commit into
mainfrom
cxymds/fix/console-session-expiration-notice
Dec 1, 2026
Merged

cxymds merged 1 commit into
mainfrom
cxymds/fix/console-session-expiration-notice

Conversation

@cxymds

@cxymds cxymds commented Dec 1, 2026

Copy link
Copy Markdown
Member

Description

Opening a dashboard route with an empty browser session could display “Your session has expired” on the login page. The dashboard guard supplied the same URL flag for visitors and expired sessions.

The guard now sends unauthenticated visitors to the plain login URL. The auth provider records a one-time warning when the current session expires or is rejected by the admin API or S3. The login page consumes that warning, and a replacement session clears any pending notice from the previous session.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • Security fix

Testing

  • Unit tests added/updated
  • Manual testing completed
pnpm install --frozen-lockfile
pnpm type-check
pnpm lint
pnpm format:check
pnpm test:run
pnpm build
git diff --check

Chrome against the local production static export verified a first visit to the Console home and Buckets pages, direct login with and without the legacy URL flag, and warnings for expired stored sessions.

Checklist

  • Code follows the project's style guidelines
  • Self-review completed
  • TypeScript types are properly defined
  • All commit messages are in English (Conventional Commits)
  • All existing tests pass
  • No new dependencies added, or they are justified

Related Issues

N/A

Screenshots (if applicable)

Viewport Before After
Desktop Desktop login with an incorrect expiration warning Desktop login on a first visit
Mobile Mobile login with an incorrect expiration warning Mobile login on a first visit

Additional Notes

N/A

Record expiration notices in the auth provider for the session that was actually invalidated. Route unauthenticated dashboard visitors to plain login and show each confirmed expiration once.

@overtrue overtrue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Review Summary

  • lib/auth-session.ts (getSessionExpiration, isValidCredentials):
    • Extracting getSessionExpiration cleanly separates structural + timestamp validity from the expiration > now check without changing isValidCredentials semantics.
  • contexts/auth-context.tsx (AuthProvider, expireSession, consumeSessionExpirationNotice):
    • Using a paired Symbol() state + ref (sessionExpiration / pendingSessionExpiration) ensures expiration notices are strictly one-shot, survive React StrictMode effect replays without duplicate toasts, and only trigger when the expired session carried a valid Expiration timestamp.
    • Clearing pendingSessionExpiration.current in login, logout, and the useLayoutEffect cross-tab authentication guard—plus verifying !isValidCredentials(getStoredCredentials()) on consume—prevents stale warnings after manual logout, cross-tab sign-out, or concurrent cross-tab login replacement.
  • components/dashboard-auth-guard.tsx, contexts/api-context.tsx, contexts/s3-context.tsx, app/(auth)/auth/login/page.tsx:
    • Removing the ?unauthorized=true query flag from redirects and consuming the auth-context notice on the login page cleanly separates anonymous visitors from expired sessions.
  • Tests (tests/hooks/use-oidc-logout.test.ts, tests/hooks/use-permissions-refresh.test.ts, tests/lib/form-interaction.test.ts):
    • Well-covered across first-visit redirects, API/S3 401 expirations, timer expirations, invalid vs expired stored credentials, StrictMode double-effect replay, cross-tab sign-out, and batched cross-tab session replacement. All 10 CI checks passed.

@cxymds
cxymds merged commit 29a44c3 into main Dec 1, 2026
10 checks passed
@cxymds
cxymds deleted the cxymds/fix/console-session-expiration-notice branch December 1, 2026 08:06
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.

2 participants