[PR #6032] [MERGED] fix(client): ensure refetchInterval triggers active network request #14644

Closed
opened 2026-04-13 09:33:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6032
Author: @GautamBytes
Created: 11/17/2025
Status: Merged
Merged: 11/17/2025
Merged by: @himself65

Base: canaryHead: fix/client-refetch-interval


📝 Commits (3)

  • fe7961c fix: trigger network fetch on session poll
  • 5bb309b fix: handle expired session (null) in refetch
  • bf2662a test: add session refresh manager tests for refetch interval

📊 Changes

2 files changed (+78 additions, -2 deletions)

View changed files

packages/better-auth/src/client/session-refresh.test.ts (+62 -0)
📝 packages/better-auth/src/client/session-refresh.ts (+16 -2)

📄 Description

Closes #6009

Description

Fixes a bug where refetchInterval in the client configuration would only update the local session signal but failed to trigger an actual network request to the backend.

This behavior broke the cookieCache refresh mechanism, as the server never received the request needed to issue a new Set-Cookie header, leading to unexpected logouts when the cookie expired.

The Fix

Updated session-refresh.ts to explicitly call $fetch("/get-session") when the polling interval fires. This ensures the session is validated against the backend and allows the server to slide/refresh the cookie expiration.

Note

Users using cookieCache should ensure their refetchInterval is set to a value lower than their cookieCache.maxAge (e.g., 4 minutes interval for a 5-minute maxAge) to prevent race conditions where the cookie expires before the fetch occurs.


Summary by cubic

Ensures refetchInterval triggers a real backend session fetch so cookies refresh on time and users don’t get logged out.

  • Bug Fixes

    • Polling now calls $fetch("/get-session") and updates sessionAtom/sessionSignal to sync with the server.
    • Restores cookieCache refresh by allowing the server to issue Set-Cookie during polls.
  • Migration

    • Set refetchInterval lower than cookieCache.maxAge (e.g., 4m interval for 5m maxAge) to avoid cookie expiry before fetch.

Written for commit bf2662aec6. Summary will update automatically on new commits.


🔄 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/6032 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 11/17/2025 **Status:** ✅ Merged **Merged:** 11/17/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/client-refetch-interval` --- ### 📝 Commits (3) - [`fe7961c`](https://github.com/better-auth/better-auth/commit/fe7961c99067f8f97f8c1a57b5458c6cf2945889) fix: trigger network fetch on session poll - [`5bb309b`](https://github.com/better-auth/better-auth/commit/5bb309bd84d8a361985210d20cdef35e4a70e99b) fix: handle expired session (null) in refetch - [`bf2662a`](https://github.com/better-auth/better-auth/commit/bf2662aec600ac499dedc26f52b6c6008dfdc94e) test: add session refresh manager tests for refetch interval ### 📊 Changes **2 files changed** (+78 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/client/session-refresh.test.ts` (+62 -0) 📝 `packages/better-auth/src/client/session-refresh.ts` (+16 -2) </details> ### 📄 Description Closes #6009 ### Description Fixes a bug where `refetchInterval` in the client configuration would only update the local session signal but failed to trigger an actual network request to the backend. This behavior broke the `cookieCache` refresh mechanism, as the server never received the request needed to issue a new `Set-Cookie` header, leading to unexpected logouts when the cookie expired. ### The Fix Updated `session-refresh.ts` to explicitly call `$fetch("/get-session")` when the polling interval fires. This ensures the session is validated against the backend and allows the server to slide/refresh the cookie expiration. ### Note Users using `cookieCache` should ensure their `refetchInterval` is set to a value **lower** than their `cookieCache.maxAge` (e.g., 4 minutes interval for a 5-minute maxAge) to prevent race conditions where the cookie expires before the fetch occurs. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Ensures refetchInterval triggers a real backend session fetch so cookies refresh on time and users don’t get logged out. - **Bug Fixes** - Polling now calls $fetch("/get-session") and updates sessionAtom/sessionSignal to sync with the server. - Restores cookieCache refresh by allowing the server to issue Set-Cookie during polls. - **Migration** - Set refetchInterval lower than cookieCache.maxAge (e.g., 4m interval for 5m maxAge) to avoid cookie expiry before fetch. <sup>Written for commit bf2662aec600ac499dedc26f52b6c6008dfdc94e. Summary will update automatically on new commits.</sup> <!-- 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-04-13 09:33:42 -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#14644