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

Closed
opened 2026-04-15 22:30:36 -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: Closed

Base: mainHead: canary


📄 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 collecting only defaulted additional fields and skipping required checks during default resolution. Plugins can 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 503e95c7fd. 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:** ❌ Closed **Base:** `main` ← **Head:** `canary` --- ### 📄 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 collecting only defaulted additional fields and skipping required checks during default resolution. Plugins can 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 503e95c7fd423b636419ce467067ddaaee8f4c85. 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-15 22:30:36 -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#24678