[PR #4930] [MERGED] perf: improve type Auth #31268

Closed
opened 2026-04-17 22:09:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4930
Author: @himself65
Created: 9/26/2025
Status: Merged
Merged: 9/27/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/09/26/type


📝 Commits (5)

📊 Changes

7 files changed (+105 additions, -32 deletions)

View changed files

📝 packages/better-auth/src/api/index.ts (+10 -7)
📝 packages/better-auth/src/api/routes/session-api.test.ts (+4 -6)
packages/better-auth/src/auth.test.ts (+60 -0)
📝 packages/better-auth/src/auth.ts (+23 -14)
📝 packages/better-auth/src/plugins/custom-session/client.ts (+6 -3)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+1 -1)
📝 packages/better-auth/src/types/api.ts (+1 -1)

📄 Description

Move it on top of Auth to reduce some deeper type inference.

Reduce perf from ~9.5s to ~8.7s

image

Summary by cubic

Made Auth generic and plugin-aware to provide precise typings for api, options, $Infer, and merged $ERROR_CODES. Added type tests to validate default Auth and plugin error code merging.

  • Refactors
    • Introduced Auth and updated betterAuth to return Auth.
    • api now derives from router endpoints via FilterActions; removed InferAPI casting.
    • $ERROR_CODES types merge InferPluginErrorCodes with BASE_ERROR_CODES.
    • $Infer exposes session/user inferred from Options and includes plugin types.
    • Added vitest type tests for default Auth and custom plugin $ERROR_CODES.

🔄 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/4930 **Author:** [@himself65](https://github.com/himself65) **Created:** 9/26/2025 **Status:** ✅ Merged **Merged:** 9/27/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/09/26/type` --- ### 📝 Commits (5) - [`b17f704`](https://github.com/better-auth/better-auth/commit/b17f70438bf0d8d03ba5661baad3679b55f1640c) feat: improve type `Auth` - [`45a2b34`](https://github.com/better-auth/better-auth/commit/45a2b34b5df8a98b6aa1604e7c41de68b4bd4cab) fix: type - [`5e7ee13`](https://github.com/better-auth/better-auth/commit/5e7ee131686630d017df6d4a9708b0ad05bce09c) fix: type - [`b90306a`](https://github.com/better-auth/better-auth/commit/b90306ada209dbd5fc0e894ad4cef02de1531dd5) fix: remove async - [`286f881`](https://github.com/better-auth/better-auth/commit/286f88191ea57024e0165f04d8e8d4ab8c08b8f8) Merge branch 'canary' into himself65/2025/09/26/type ### 📊 Changes **7 files changed** (+105 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/index.ts` (+10 -7) 📝 `packages/better-auth/src/api/routes/session-api.test.ts` (+4 -6) ➕ `packages/better-auth/src/auth.test.ts` (+60 -0) 📝 `packages/better-auth/src/auth.ts` (+23 -14) 📝 `packages/better-auth/src/plugins/custom-session/client.ts` (+6 -3) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+1 -1) 📝 `packages/better-auth/src/types/api.ts` (+1 -1) </details> ### 📄 Description Move it on top of `Auth` to reduce some deeper type inference. Reduce perf from ~9.5s to ~8.7s <img width="1104" height="353" alt="image" src="https://github.com/user-attachments/assets/da6bb711-7c5c-45c4-b4f8-6896a48fff75" /> <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Made Auth generic and plugin-aware to provide precise typings for api, options, $Infer, and merged $ERROR_CODES. Added type tests to validate default Auth and plugin error code merging. - **Refactors** - Introduced Auth<Options> and updated betterAuth to return Auth<Options>. - api now derives from router<Options> endpoints via FilterActions; removed InferAPI casting. - $ERROR_CODES types merge InferPluginErrorCodes<Options> with BASE_ERROR_CODES. - $Infer exposes session/user inferred from Options and includes plugin types. - Added vitest type tests for default Auth and custom plugin $ERROR_CODES. <!-- 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-17 22:09:38 -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#31268