[PR #8145] fix(core): avoid throwing on required session fields when collecting defaults #7778

Open
opened 2026-03-13 13:48:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8145
Author: @AlexStrNik
Created: 2/25/2026
Status: 🔄 Open

Base: canaryHead: canary


📝 Commits (1)

  • d5bdf70 fix(core): avoid throwing on required session fields when collecting defaults

📊 Changes

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

View changed files

📝 packages/better-auth/src/db/internal-adapter.ts (+2 -2)
📝 packages/better-auth/src/db/schema.ts (+14 -0)

📄 Description

parseSessionInput in packages/better-auth/src/db/internal-adapter.ts was being called with an empty object to get default values for session additional fields. The problem is this runs through parseInputData which validates required fields — so if any plugin adds a required field to the session schema, it throws before the database hooks even get a chance to run. Introduced in #5763

Added getSessionDefaultFields helper in packages/better-auth/src/db/schema.ts that just collects fields with default values without doing any required field validation. Replaced the parseSessionInput({}) call with it.


Summary by cubic

Prevented a session creation crash by reading only defaulted additional fields and skipping required field checks during default collection. Plugins can now add required session fields without blocking DB hooks.

  • Bug Fixes
    • Added getSessionDefaultFields to return only defaults; replaced parseSessionInput(options, {}) in the internal adapter.

Written for commit d5bdf70024. 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/8145 **Author:** [@AlexStrNik](https://github.com/AlexStrNik) **Created:** 2/25/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (1) - [`d5bdf70`](https://github.com/better-auth/better-auth/commit/d5bdf7002419eae72d33f0fd38b47038b8e9e00c) fix(core): avoid throwing on required session fields when collecting defaults ### 📊 Changes **2 files changed** (+16 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.ts` (+2 -2) 📝 `packages/better-auth/src/db/schema.ts` (+14 -0) </details> ### 📄 Description `parseSessionInput` in `packages/better-auth/src/db/internal-adapter.ts` was being called with an empty object to get default values for session additional fields. The problem is this runs through `parseInputData` which validates required fields — so if any plugin adds a required field to the session schema, it throws before the database hooks even get a chance to run. Introduced in #5763 Added `getSessionDefaultFields` helper in `packages/better-auth/src/db/schema.ts` that just collects fields with default values without doing any required field validation. Replaced the `parseSessionInput({})` call with it. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevented a session creation crash by reading only defaulted additional fields and skipping required field checks during default collection. Plugins can now add required session fields without blocking DB hooks. - **Bug Fixes** - Added getSessionDefaultFields to return only defaults; replaced parseSessionInput(options, {}) in the internal adapter. <sup>Written for commit d5bdf7002419eae72d33f0fd38b47038b8e9e00c. 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:48:53 -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#7778