[PR #3396] [CLOSED] fix: allow partial session data in database hooks #21701

Closed
opened 2026-04-15 20:32:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3396
Author: @othompson2
Created: 7/15/2025
Status: Closed

Base: mainHead: fix/session-database-hooks-partial-data


📝 Commits (1)

  • 767c8aa fix: allow partial session data in database hooks

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/types/options.ts (+1 -1)

📄 Description

Summary

  • Fixed session database hooks to accept Partial<Session> instead of requiring complete Session objects
  • Makes session hooks consistent with user hooks behavior
  • Resolves issues where setActiveOrganization and similar functions fail when using database hooks with partial updates

Problem

Session update database hooks were typed to require complete Session objects in their return value:

data: Session & Record<string, any>;

This was inconsistent with user update hooks which correctly accept partial data:

data: Partial<User> & Record<string, any>;

This caused TypeScript errors when database hooks returned only the partial data being updated, as the missing fields would be undefined.

Solution

Changed the session database hook type definition to accept partial data:

data: Partial<Session> & Record<string, any>;

Test plan

  • Verify TypeScript compilation passes
  • Test setActiveOrganization with database hooks
  • Ensure other session update operations work with hooks
  • Run existing test suite to ensure no regressions

🤖 Generated with Claude Code


Summary by cubic

Session database hooks now accept partial session data, matching the behavior of user hooks and fixing errors with partial updates like setActiveOrganization.


🔄 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/3396 **Author:** [@othompson2](https://github.com/othompson2) **Created:** 7/15/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/session-database-hooks-partial-data` --- ### 📝 Commits (1) - [`767c8aa`](https://github.com/better-auth/better-auth/commit/767c8aa8e1e44034a2b995943a06ad5d6f3cef0c) fix: allow partial session data in database hooks ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/types/options.ts` (+1 -1) </details> ### 📄 Description ## Summary - Fixed session database hooks to accept `Partial<Session>` instead of requiring complete `Session` objects - Makes session hooks consistent with user hooks behavior - Resolves issues where `setActiveOrganization` and similar functions fail when using database hooks with partial updates ## Problem Session update database hooks were typed to require complete `Session` objects in their return value: ```typescript data: Session & Record<string, any>; ``` This was inconsistent with user update hooks which correctly accept partial data: ```typescript data: Partial<User> & Record<string, any>; ``` This caused TypeScript errors when database hooks returned only the partial data being updated, as the missing fields would be `undefined`. ## Solution Changed the session database hook type definition to accept partial data: ```typescript data: Partial<Session> & Record<string, any>; ``` ## Test plan - [x] Verify TypeScript compilation passes - [ ] Test `setActiveOrganization` with database hooks - [ ] Ensure other session update operations work with hooks - [ ] Run existing test suite to ensure no regressions 🤖 Generated with [Claude Code](https://claude.ai/code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Session database hooks now accept partial session data, matching the behavior of user hooks and fixing errors with partial updates like setActiveOrganization. <!-- 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 20:32: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#21701