[PR #8146] [MERGED] fix(core): avoid throwing on required session fields when collecting defaults #16025

Closed
opened 2026-04-13 10:21:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8146
Author: @AlexStrNik
Created: 2/25/2026
Status: Merged
Merged: 2/28/2026
Merged by: @Bekacru

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

Fixed session creation failing when plugins add required session fields by collecting default values without running validation. Introduces getSessionDefaultFields and updates the internal adapter to use it.

  • Bug Fixes
    • Added getSessionDefaultFields to read session defaults without required checks.
    • Replaced parseSessionInput usage in the internal adapter so DB hooks can handle required fields without early errors.

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/8146 **Author:** [@AlexStrNik](https://github.com/AlexStrNik) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/28/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **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 Fixed session creation failing when plugins add required session fields by collecting default values without running validation. Introduces getSessionDefaultFields and updates the internal adapter to use it. - **Bug Fixes** - Added getSessionDefaultFields to read session defaults without required checks. - Replaced parseSessionInput usage in the internal adapter so DB hooks can handle required fields without early errors. <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-04-13 10:21:17 -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#16025