Skip to content

feat(web): enable activity-driven session heartbeat#1474

Merged
losolio merged 1 commit into
mainfrom
feat/auth-heartbeat-wire
May 24, 2026
Merged

feat(web): enable activity-driven session heartbeat#1474
losolio merged 1 commit into
mainfrom
feat/auth-heartbeat-wire

Conversation

@losolio
Copy link
Copy Markdown
Contributor

@losolio losolio commented May 21, 2026

Summary

Wires the heartbeat machinery from #1470 (activity tracker) and #1473 (hook + handler) into the web app:

  • New POST /api/auth/heartbeat route that delegates to handleHeartbeat({ oauthConfig })
  • useHeartbeat invoked from the root Providers so every authenticated user benefits. On 401, dispatches sessionExpired to the existing authStore.

Final 3/3 of the heartbeat work:

Why

Auth0's idle refresh-token lifetime cuts off active users who don't navigate — typically someone editing a long form or scribo callout. Symptom: "logged out while typing." With this in place, the client refreshes the access token every ~5 min while the user is actually interacting (mouse/keyboard/touch/focus within the last 2 min). Background tabs are skipped, and a tab regaining focus after a long away triggers an immediate refresh.

Together with the planned Auth0 lifetime adjustment (access 15 min / idle 30 min / max 8 h), this should eliminate the reports.

Test plan

  • pnpm dev in apps/web — log in, leave a form open for >5 min while typing occasionally, confirm /api/auth/heartbeat returns 200 and the session cookie is rotated
  • DevTools → Network: heartbeat tick fires every 5 min, only when interacting in the last 2 min
  • DevTools → switch tab away for 6 min, switch back: immediate heartbeat fires
  • Force-expire the refresh token (e.g. Auth0 revoke session): next heartbeat returns 401 and sessionExpired is dispatched

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 21, 2026 21:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the activity-driven session heartbeat feature for apps/web by adding a server route that refreshes the current session and wiring the client-side useHeartbeat hook into the app’s root provider layer.

Changes:

  • Add POST /api/auth/heartbeat route that delegates to @eventuras/fides-auth-next’s handleHeartbeat.
  • Invoke useHeartbeat from Providers and dispatch sessionExpired on 401 to the existing authStore.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/web/src/app/Providers.tsx Starts the client heartbeat logic globally and connects 401 handling to authStore.sessionExpired.
apps/web/src/app/(auth)/api/auth/heartbeat/route.ts Adds the heartbeat API route that performs server-side session refresh via handleHeartbeat.

Comment thread apps/web/src/app/Providers.tsx Outdated
Wires the heartbeat from @eventuras/fides-auth-next into apps/web:

- New `/api/auth/heartbeat` POST route that delegates to the
  `handleHeartbeat` factory with the app's `oauthConfig`
- `useHeartbeat` hook invoked from the root `Providers` so every
  authenticated user benefits — dispatches `sessionExpired` to the
  auth store on 401

Final 3/3 of the heartbeat work. Together with #1470 and #1473, this
should stop the "logged out while typing" reports for active users.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@losolio losolio force-pushed the feat/auth-heartbeat-wire branch from 6c7033f to 6e6399d Compare May 23, 2026 23:01
@sonarqubecloud
Copy link
Copy Markdown

@losolio losolio merged commit 0b704f8 into main May 24, 2026
15 checks passed
@losolio losolio deleted the feat/auth-heartbeat-wire branch May 24, 2026 14:02
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Eventuras backlog May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants