[PR #5630] [MERGED] feat(client): refetch session when browser state changes #6126

Closed
opened 2026-03-13 12:48:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5630
Author: @himself65
Created: 10/28/2025
Status: Merged
Merged: 10/28/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/10/27/revalidate-logic


📝 Commits (2)

  • e1a6bc2 feat(client): refetch session when browser state changes
  • 09bde5b Update packages/core/src/types/plugin-client.ts

📊 Changes

6 files changed (+273 additions, -3 deletions)

View changed files

packages/better-auth/src/client/broadcast-channel.ts (+34 -0)
📝 packages/better-auth/src/client/config.ts (+1 -1)
📝 packages/better-auth/src/client/index.ts (+2 -0)
📝 packages/better-auth/src/client/session-atom.ts (+25 -2)
packages/better-auth/src/client/session-refresh.ts (+180 -0)
📝 packages/core/src/types/plugin-client.ts (+31 -0)

📄 Description

Summary by cubic

Automatically keeps the auth session up to date by refetching on window focus, online status changes, cross-tab updates, and optional polling. This reduces stale user state and keeps sessions consistent across tabs.

  • New Features
    • Added a session refresh manager that refetches on:
      • window focus (visibilitychange)
      • going online/offline
      • cross-tab updates via localStorage (broadcast channel)
      • optional polling (refetchInterval)
    • New client config: sessionOptions
      • refetchInterval (seconds, default 0)
      • refetchOnWindowFocus (default true)
      • refetchWhenOffline (default false)
    • getSessionAtom now initializes the refresh manager and toggles $sessionSignal to refetch; includes proper cleanup
    • Exported broadcast-channel and session-refresh from the client package

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5630 **Author:** [@himself65](https://github.com/himself65) **Created:** 10/28/2025 **Status:** ✅ Merged **Merged:** 10/28/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/10/27/revalidate-logic` --- ### 📝 Commits (2) - [`e1a6bc2`](https://github.com/better-auth/better-auth/commit/e1a6bc2ad9b47dd216d1f79c8614d089c5aa4b0e) feat(client): refetch session when browser state changes - [`09bde5b`](https://github.com/better-auth/better-auth/commit/09bde5be117ec0dc80e1af32058d2c2161cd64d4) Update packages/core/src/types/plugin-client.ts ### 📊 Changes **6 files changed** (+273 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/client/broadcast-channel.ts` (+34 -0) 📝 `packages/better-auth/src/client/config.ts` (+1 -1) 📝 `packages/better-auth/src/client/index.ts` (+2 -0) 📝 `packages/better-auth/src/client/session-atom.ts` (+25 -2) ➕ `packages/better-auth/src/client/session-refresh.ts` (+180 -0) 📝 `packages/core/src/types/plugin-client.ts` (+31 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Automatically keeps the auth session up to date by refetching on window focus, online status changes, cross-tab updates, and optional polling. This reduces stale user state and keeps sessions consistent across tabs. - **New Features** - Added a session refresh manager that refetches on: - window focus (visibilitychange) - going online/offline - cross-tab updates via localStorage (broadcast channel) - optional polling (refetchInterval) - New client config: sessionOptions - refetchInterval (seconds, default 0) - refetchOnWindowFocus (default true) - refetchWhenOffline (default false) - getSessionAtom now initializes the refresh manager and toggles $sessionSignal to refetch; includes proper cleanup - Exported broadcast-channel and session-refresh from the client package <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:48:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6126