Skip to content

feat(platform): warn and sign out idle sessions client-side - #1810

Merged
yannickmonney merged 1 commit into
mainfrom
feat/session-idle-watchdog
Jun 1, 2026
Merged

yannickmonney merged 1 commit into
mainfrom
feat/session-idle-watchdog

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What

Completes the session idle timeout (#1502) with its client-side UX. The server enforcement merged in #1808 — Better Auth rejects an over-idle session on the next request when SESSION_IDLE_TIMEOUT_MINUTES is set. This adds the matching watchdog so a user is warned and signed out proactively instead of silently 401-ing on their next action. Part of the security baseline epic.

How

  • useSessionIdleWatchdog watches local input (mousemove, mousedown, keydown, touchstart, scroll, wheel, plus visibilitychange), shows a warning toast one minute before the cut-off with a Stay signed in action, and at the window calls authClient.signOut() then hard-redirects to /log-in (full reload to flush Convex/React-Query/auth state, matching the existing sign-out precedent).
  • Cross-tab: the last-activity timestamp is shared via localStorage and re-read each tick, so an idle background tab doesn't sign out a user who is active in another tab — mirroring the server's sliding window.
  • No-op unless the timeout is configured.
  • The validated window is exposed to the client via window.__ENV__ (server.ts + the dev inject-env plugin) and read through a typed getEnv overload; it is omitted entirely when the feature is off.
  • Mounted once in the authenticated dashboard layout. en/de/fr strings added.

Tests

use-session-idle-watchdog.test.tsx — fake-timer coverage for: no-op when unconfigured, warn-then-sign-out at the thresholds, activity resets the timer, and the warning is dismissed when the user returns (4 cases).

Verification

typecheck · lint · test (ui + server) · i18n parity/usage all green. CodeRabbit applied (documented the intentional hard reload; added a focus-visible ring + motion-reduce to the toast action).

Refs #1502. Tracked under the security baseline epic #1803.

Completes the session idle timeout (#1502). The server already enforces the
window (Better Auth rejects an over-idle session on the next request when
SESSION_IDLE_TIMEOUT_MINUTES is set). This adds the matching client UX so a
user is warned and signed out proactively instead of silently 401-ing on
their next action.

- useSessionIdleWatchdog watches local input (mousemove/keydown/scroll/…),
  shows a warning toast one minute before the cut-off with a "Stay signed
  in" action, and calls authClient.signOut() + redirects to /log-in at the
  window. Cross-tab activity is shared via localStorage so an idle background
  tab doesn't sign out a user working in another. No-op when the timeout is
  unset.
- The validated window is exposed to the client via window.__ENV__
  (server.ts + the dev inject-env plugin) and read through a typed getEnv
  overload; it is omitted entirely when the feature is off.
- Mounted in the authenticated dashboard layout. en/de/fr strings added.

Tests: fake-timer coverage for the disabled, warn→sign-out, activity-reset,
and warning-dismissal paths.

Refs #1502, #1803
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@yannickmonney, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 minutes and 15 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d8ac91aa-b31c-4e70-9483-cddba7461905

📥 Commits

Reviewing files that changed from the base of the PR and between 0c56486 and ea64401.

📒 Files selected for processing (9)
  • services/platform/app/hooks/use-session-idle-watchdog.test.tsx
  • services/platform/app/hooks/use-session-idle-watchdog.tsx
  • services/platform/app/routes/dashboard.tsx
  • services/platform/lib/env.ts
  • services/platform/messages/de.json
  • services/platform/messages/en.json
  • services/platform/messages/fr.json
  • services/platform/server.ts
  • services/platform/vite-plugins/inject-env.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/session-idle-watchdog

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yannickmonney
yannickmonney merged commit d8068d8 into main Jun 1, 2026
28 checks passed
@yannickmonney
yannickmonney deleted the feat/session-idle-watchdog branch June 1, 2026 23:43
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.

1 participant