[PR #5804] [CLOSED] fix(internal-adapter): initialize and persist plugin session fields in secondary storage #6236

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5804
Author: @bytaesu
Created: 11/6/2025
Status: Closed

Base: canaryHead: 2025-11-06/fix/internal-adapter-session


📝 Commits (6)

  • ef4cb0a fix: initialize and persist plugin session fields in secondary storage
  • 51373ab test: add test cases for plugin session fields in secondary storage
  • 4877ec8 perf: memoize plugin sesion fields at initialization
  • 8c9ca19 fix: handle function defaultValue in plugin session fields
  • 7166b5c fix: evaluate function defaultValues on session creation
  • dce204c fix: check field property existence with 'in' operator

📊 Changes

2 files changed (+293 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.test.ts (+237 -0)
📝 packages/better-auth/src/db/internal-adapter.ts (+56 -0)

📄 Description

This PR fixes an issue where additional session fields in the plugin disappear when using secondary storage.


Summary by cubic

Fixes loss of plugin-defined session fields when using secondary storage. Plugin fields are now initialized and persisted so findSession returns them reliably.

  • Bug Fixes
    • Initialize plugin session fields on create (evaluate function defaultValue; use null for optional fields).
    • Persist updates to secondary storage with a TTL derived from expiresAt.
    • Ensure findSession reads plugin fields when sessions are stored only in secondary storage.
    • Added tests for initialization, update preservation, and retrieval.

Written for commit dce204cdd3. 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/5804 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 11/6/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `2025-11-06/fix/internal-adapter-session` --- ### 📝 Commits (6) - [`ef4cb0a`](https://github.com/better-auth/better-auth/commit/ef4cb0a4d4ebc39fb786b76e467ab6f3b8eb4bf6) fix: initialize and persist plugin session fields in secondary storage - [`51373ab`](https://github.com/better-auth/better-auth/commit/51373ab3eeaa92e1a9e4a92e20ae68d53b0063ce) test: add test cases for plugin session fields in secondary storage - [`4877ec8`](https://github.com/better-auth/better-auth/commit/4877ec85c2ba8ab7c60c05ecbafb9dd10af54447) perf: memoize plugin sesion fields at initialization - [`8c9ca19`](https://github.com/better-auth/better-auth/commit/8c9ca19a218a2099acfbaaf29e40a77036d83d3d) fix: handle function defaultValue in plugin session fields - [`7166b5c`](https://github.com/better-auth/better-auth/commit/7166b5c1908d80d19e91e9bd68518bf8f42b2a42) fix: evaluate function defaultValues on session creation - [`dce204c`](https://github.com/better-auth/better-auth/commit/dce204cdd3f4e8101e014121772c4be5c17b24ca) fix: check field property existence with 'in' operator ### 📊 Changes **2 files changed** (+293 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.test.ts` (+237 -0) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+56 -0) </details> ### 📄 Description This PR fixes an issue where additional session fields in the plugin disappear when using secondary storage. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes loss of plugin-defined session fields when using secondary storage. Plugin fields are now initialized and persisted so findSession returns them reliably. - **Bug Fixes** - Initialize plugin session fields on create (evaluate function defaultValue; use null for optional fields). - Persist updates to secondary storage with a TTL derived from expiresAt. - Ensure findSession reads plugin fields when sessions are stored only in secondary storage. - Added tests for initialization, update preservation, and retrieval. <sup>Written for commit dce204cdd3f4e8101e014121772c4be5c17b24ca. 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 12:51:58 -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#6236