[GH-ISSUE #4793] fix(types): databaseHooks.session.update.before provides a partial session but expects a full session back #27394

Closed
opened 2026-04-17 18:23:59 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @SkepticMystic on GitHub (Sep 21, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4793

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

The hook triggers on update, therefor the data available on the session arg is partial, makes sense. But the types expect a full Required session back. This is inaccurate, the adapters work just fine with the partial session, they're just applying a patch.

Current vs. Expected behavior

Change the expected output type to be partial as well

What version of Better Auth are you using?

1.13.13

System info

Doesn't run for me...

Which area(s) are affected? (Select all that apply)

Types

Auth config (if applicable)

databaseHooks: {
        session: {
          update: {
            before: async (session, ctx) => {
              return { data: session };
            },
          }
        }
      }

Additional context

No response

Originally created by @SkepticMystic on GitHub (Sep 21, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4793 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce The hook triggers on update, therefor the data available on the `session` arg is partial, makes sense. But the types expect a full `Required` session back. This is inaccurate, the adapters work just fine with the partial session, they're just applying a patch. ### Current vs. Expected behavior Change the expected output type to be partial as well ### What version of Better Auth are you using? 1.13.13 ### System info ```bash Doesn't run for me... ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript databaseHooks: { session: { update: { before: async (session, ctx) => { return { data: session }; }, } } } ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 18:23:59 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 21, 2025):

You're right—databaseHooks.session.update.before receives only the fields being updated (a partial session), but the current type definition expects a full session object as the return value, which is inaccurate for update operations. This mismatch is confirmed and is causing TypeScript errors when returning partial data, even though adapters work fine with patches "issue discussion".

There's an open pull request that proposes changing the type definition to accept Partial<Session> instead of requiring a complete session object, making session hooks consistent with user hooks and resolving issues with partial updates "PR #3396". This fix isn't available in v1.13.13 yet.

For now, you can work around this by using a type assertion (e.g., return { data: session as any }) or by extending the types locally until the PR is merged. Once the fix lands, you won't need these workarounds.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3315529738 --> @dosubot[bot] commented on GitHub (Sep 21, 2025): <!-- Answer --> You're right—`databaseHooks.session.update.before` receives only the fields being updated (a partial session), but the current type definition expects a full session object as the return value, which is inaccurate for update operations. This mismatch is confirmed and is causing TypeScript errors when returning partial data, even though adapters work fine with patches ["issue discussion"](https://github.com/better-auth/better-auth/issues/4767). There's an open pull request that proposes changing the type definition to accept `Partial<Session>` instead of requiring a complete session object, making session hooks consistent with user hooks and resolving issues with partial updates ["PR #3396"](https://github.com/better-auth/better-auth/pull/3396). This fix isn't available in v1.13.13 yet. For now, you can work around this by using a type assertion (e.g., `return { data: session as any }`) or by extending the types locally until the PR is merged. Once the fix lands, you won't need these workarounds. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/62a80775-ad1b-4dca-a414-2feaf83176dd?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4793)
Author
Owner

@SkepticMystic commented on GitHub (Sep 21, 2025):

Ok yeah, there's a PR with no linked issue, thanks bot 👍🏼

<!-- gh-comment-id:3315531130 --> @SkepticMystic commented on GitHub (Sep 21, 2025): Ok yeah, there's a PR with no linked issue, thanks bot 👍🏼
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27394