[PR #6988] [MERGED] fix: sync updateSession changes to secondary storage and active-sessions list #7010

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6988
Author: @Ridhim-RR
Created: 12/24/2025
Status: Merged
Merged: 12/30/2025
Merged by: @himself65

Base: canaryHead: fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage


📝 Commits (10+)

  • 0edc89e fix(updateSession): updateSession stale data resolved
  • 5d769d8 Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage
  • 5697591 Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage
  • 650bceb Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage
  • 84e3fb0 Merge branch 'fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage' of https://github.com/Ridhim-RR/better-auth into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage
  • bd3210b chore(testCase): Added test case
  • c9196bb chore(lint): linting issue resolved
  • 5a8c0a7 Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage
  • 9f1e54c sync files with canary
  • ebf6b3e fix: wrong body schema

📊 Changes

2 files changed (+187 additions, -13 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.test.ts (+116 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+71 -13)

📄 Description

closes #6987

Summary
Fix updateSession so session refreshes are persisted when using secondary storage.
Keep active-sessions-{userId} list in sync with refreshed expiry/TTL.

Problem

  • Session refresh updated the cookie but didn’t write the new expiresAt (or TTL) back to secondary storage, leaving stale cache entries and mappings.

Fix:

  • In updateSession secondary-storage path:
  • Write the merged session back to sessionToken with refreshed TTL.
  • Rebuild active-sessions-{userId} (drop expired, replace this token’s entry, set TTL to furthest expiry).

Summary by cubic

Persist session refreshes to secondary storage and sync the active-sessions list to prevent stale entries after updateSession. Addresses Linear #6987.

  • Bug Fixes
    • Write the merged session back to sessionToken with the refreshed TTL.
    • Rebuild active-sessions-{userId}: drop expired items, replace this token’s entry, set list TTL to the furthest expiry.
    • Skip writes when TTL <= 0 and delete the list if no valid sessions remain.

Written for commit bf4dcc24e8. 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/6988 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 12/24/2025 **Status:** ✅ Merged **Merged:** 12/30/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage` --- ### 📝 Commits (10+) - [`0edc89e`](https://github.com/better-auth/better-auth/commit/0edc89e025f48679b01f4b12ef670aebfdcf61c1) fix(updateSession): updateSession stale data resolved - [`5d769d8`](https://github.com/better-auth/better-auth/commit/5d769d8393d39d6598508d734c1127845804d881) Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage - [`5697591`](https://github.com/better-auth/better-auth/commit/5697591dcf31d0671389a6271e024f45e1b13bf4) Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage - [`650bceb`](https://github.com/better-auth/better-auth/commit/650bcebf6a31db0c19029282e65ef0847a28bf8c) Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage - [`84e3fb0`](https://github.com/better-auth/better-auth/commit/84e3fb0ed7683e3b86ebd8443d6b51075c78586f) Merge branch 'fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage' of https://github.com/Ridhim-RR/better-auth into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage - [`bd3210b`](https://github.com/better-auth/better-auth/commit/bd3210bb0c7f408de24bf78bc2e0d6415af14d3d) chore(testCase): Added test case - [`c9196bb`](https://github.com/better-auth/better-auth/commit/c9196bb3219ee978b97d9d2e95398d637dff88cc) chore(lint): linting issue resolved - [`5a8c0a7`](https://github.com/better-auth/better-auth/commit/5a8c0a732cb1ef8ceb54c74e4a4859b4b3448969) Merge branch 'canary' into fix/updateSession-doesn’t-persist-updated-data-to-secondary-storage - [`9f1e54c`](https://github.com/better-auth/better-auth/commit/9f1e54c9658ab148027cbb91584941a6ce1f9a73) sync files with canary - [`ebf6b3e`](https://github.com/better-auth/better-auth/commit/ebf6b3efd47aede1390043a16f634a8c9710b9b6) fix: wrong body schema ### 📊 Changes **2 files changed** (+187 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+116 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+71 -13) </details> ### 📄 Description closes #6987 **Summary** Fix updateSession so session refreshes are persisted when using secondary storage. Keep active-sessions-{userId} list in sync with refreshed expiry/TTL. **Problem** - Session refresh updated the cookie but didn’t write the new expiresAt (or TTL) back to secondary storage, leaving stale cache entries and mappings. **Fix:** - In updateSession secondary-storage path: - Write the merged session back to sessionToken with refreshed TTL. - Rebuild active-sessions-{userId} (drop expired, replace this token’s entry, set TTL to furthest expiry). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Persist session refreshes to secondary storage and sync the active-sessions list to prevent stale entries after updateSession. Addresses Linear #6987. - **Bug Fixes** - Write the merged session back to sessionToken with the refreshed TTL. - Rebuild active-sessions-{userId}: drop expired items, replace this token’s entry, set list TTL to the furthest expiry. - Skip writes when TTL <= 0 and delete the list if no valid sessions remain. <sup>Written for commit bf4dcc24e860aef641c959026c4b901b323b914a. 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-03-13 13:21:05 -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#7010