[PR #7619] [CLOSED] fix(next-js): skip session refresh in RSC context to prevent cookie desync #7445

Closed
opened 2026-03-13 13:36:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7619
Author: @adamsbytes
Created: 1/26/2026
Status: Closed

Base: canaryHead: fix/session-refresh-rsc-desync


📝 Commits (3)

  • ce821d3 feat(next-js): detect RSC context in nextCookies plugin
  • 075d587 fix(session): skip DB refresh when _skipSessionRefresh flag is set
  • 8d915c8 test(session): add RSC context session refresh tests

📊 Changes

3 files changed (+141 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session-api.test.ts (+108 -0)
📝 packages/better-auth/src/api/routes/session.ts (+14 -0)
📝 packages/better-auth/src/integrations/next-js.ts (+19 -0)

📄 Description

Closes #2115

getSession() in RSC would refresh the session in DB but couldn't update the cookie, causing desync. This detects RSC context via the RSC header and skips the refresh. Server Actions still work since they can set cookies.


Summary by cubic

Skip session refresh in Next.js RSC to prevent DB/cookie desync. Server Actions still refresh since they can set cookies. Addresses #2115.

  • Bug Fixes
    • Detect RSC via the RSC header in nextCookies and set a _skipSessionRefresh flag.
    • Respect the flag in getSession to avoid DB refresh when cookies can’t be updated.
    • Allow refresh during Server Actions when Next-Action is present.
    • Added tests for RSC skip, Server Action refresh, and normal refresh.

Written for commit 8d915c8afc. Summary will update 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/7619 **Author:** [@adamsbytes](https://github.com/adamsbytes) **Created:** 1/26/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/session-refresh-rsc-desync` --- ### 📝 Commits (3) - [`ce821d3`](https://github.com/better-auth/better-auth/commit/ce821d30b04051924a2582339818da927895e3a8) feat(next-js): detect RSC context in nextCookies plugin - [`075d587`](https://github.com/better-auth/better-auth/commit/075d587b680623c929ffdd388381788cc3c26877) fix(session): skip DB refresh when _skipSessionRefresh flag is set - [`8d915c8`](https://github.com/better-auth/better-auth/commit/8d915c8afce05d3768d92d13cdf44e8624f1464f) test(session): add RSC context session refresh tests ### 📊 Changes **3 files changed** (+141 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+108 -0) 📝 `packages/better-auth/src/api/routes/session.ts` (+14 -0) 📝 `packages/better-auth/src/integrations/next-js.ts` (+19 -0) </details> ### 📄 Description Closes #2115 `getSession()` in RSC would refresh the session in DB but couldn't update the cookie, causing desync. This detects RSC context via the `RSC` header and skips the refresh. Server Actions still work since they can set cookies. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Skip session refresh in Next.js RSC to prevent DB/cookie desync. Server Actions still refresh since they can set cookies. Addresses #2115. - **Bug Fixes** - Detect RSC via the RSC header in nextCookies and set a _skipSessionRefresh flag. - Respect the flag in getSession to avoid DB refresh when cookies can’t be updated. - Allow refresh during Server Actions when Next-Action is present. - Added tests for RSC skip, Server Action refresh, and normal refresh. <sup>Written for commit 8d915c8afce05d3768d92d13cdf44e8624f1464f. Summary will update 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-03-13 13:36:41 -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#7445