[PR #5009] [MERGED] fix(custom-session): Infer.Session to infer the return type of the custom session #5715

Closed
opened 2026-03-13 12:32:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5009
Author: @Bekacru
Created: 10/1/2025
Status: Merged
Merged: 10/2/2025
Merged by: @Bekacru

Base: canaryHead: fix/custom-session


📝 Commits (2)

  • 3fb5a65 fix(custom-session): should force .Session to infer the return type of the fn
  • 53b9aa2 chore: remove runtime usage of infer

📊 Changes

5 files changed (+50 additions, -27 deletions)

View changed files

📝 packages/better-auth/src/auth.ts (+14 -16)
📝 packages/better-auth/src/client/client.test.ts (+2 -2)
📝 packages/better-auth/src/plugins/custom-session/custom-session.test.ts (+22 -1)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+3 -0)
📝 packages/better-auth/src/types/types.test.ts (+9 -8)

📄 Description

closes #4584
closes #4875
closes #2818


Summary by cubic

Fixes type inference for custom sessions so auth.$Infer.Session matches the return type of the customSession handler. Adds a safe fallback to default session and user types when no plugin overrides them.

  • Bug Fixes
    • customSession exposes $Infer.Session as Awaited<ReturnType>.
    • Auth.$Infer now prefers plugin-provided Session; otherwise uses default { session, user }.
    • Added a type test to verify session type inference.

🔄 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/5009 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 10/1/2025 **Status:** ✅ Merged **Merged:** 10/2/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/custom-session` --- ### 📝 Commits (2) - [`3fb5a65`](https://github.com/better-auth/better-auth/commit/3fb5a65738420fffc754ad11bdef6046c4a1d5a4) fix(custom-session): should force .Session to infer the return type of the fn - [`53b9aa2`](https://github.com/better-auth/better-auth/commit/53b9aa2075362454525c2e4dac02cc1a4d3d7c61) chore: remove runtime usage of infer ### 📊 Changes **5 files changed** (+50 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/auth.ts` (+14 -16) 📝 `packages/better-auth/src/client/client.test.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/custom-session/custom-session.test.ts` (+22 -1) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+3 -0) 📝 `packages/better-auth/src/types/types.test.ts` (+9 -8) </details> ### 📄 Description closes #4584 closes #4875 closes #2818 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes type inference for custom sessions so auth.$Infer.Session matches the return type of the customSession handler. Adds a safe fallback to default session and user types when no plugin overrides them. - **Bug Fixes** - customSession exposes $Infer.Session as Awaited<ReturnType<fn>>. - Auth.$Infer now prefers plugin-provided Session; otherwise uses default { session, user }. - Added a type test to verify session type inference. <!-- 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 12:32:41 -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#5715