[PR #5170] [CLOSED] WIP Feat: Better Types #14068

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5170
Author: @R5dan
Created: 10/8/2025
Status: Closed

Base: mainHead: feat/better-types


📝 Commits (10+)

📊 Changes

59 files changed (+2426 additions, -1137 deletions)

View changed files

📝 .vscode/settings.json (+1 -1)
📝 docs/app/docs/[[...slug]]/page.tsx (+2 -0)
📝 docs/components/icons.tsx (+23 -0)
docs/components/mdx/add-to-cursor.tsx (+41 -0)
📝 docs/components/sidebar-content.tsx (+5 -0)
📝 docs/content/docs/concepts/database.mdx (+2 -1)
docs/content/docs/integrations/convex.mdx (+347 -0)
📝 docs/content/docs/introduction.mdx (+48 -7)
📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+106 -131)
📝 packages/better-auth/src/adapters/adapter-factory/types.ts (+62 -50)
📝 packages/better-auth/src/adapters/kysely-adapter/dialect.ts (+9 -6)
📝 packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (+21 -11)
📝 packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts (+10 -6)
📝 packages/better-auth/src/api/call.ts (+42 -11)
📝 packages/better-auth/src/api/index.ts (+17 -14)
📝 packages/better-auth/src/api/routes/session.ts (+5 -1)
📝 packages/better-auth/src/api/routes/sign-up.ts (+6 -2)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+23 -18)
📝 packages/better-auth/src/auth.ts (+15 -12)
📝 packages/better-auth/src/client/index.ts (+10 -2)

...and 39 more files

📄 Description

This is a PR to add more type safety to Better Auth, specifically in regards to accessing and editing the database via endpoints and plugins.

This PR got a lot bigger than I thought, hence why I have made the PR now, to get confirmation to keep going with this, help with some aspects and to make sure I am not misunderstanding certain types / functionality, and would appreciate any help given.

Main Functionality:

  • Plugins now have there adapter types changed to include there own types
  • Hooks and middleware also have database changes
  • Database fields have typed values for config options such as defaultValue based on the field type provide

I believe now that I have branched from the wrong branch, and am happy to migrate it to the correct one if needed. I also don't know why there are other commits as I am branching and merging to the same branch.


Summary by cubic

Introduces schema-aware generics across Better Auth to provide end-to-end type safety for adapters, APIs, hooks, and plugins. Adds a typed field builder, stronger model inference, and updates docs (Convex integration and Cursor MCP link).

  • New Features

    • Schema-aware generics: BetterAuthOptions, AuthContext, GenericEndpointContext, TransactionAdapter, and adapters now infer types from your AuthPluginSchema.
    • Typed fields via field(type, config): defaultValue and input/returned/required are now type-checked per field.
    • Internal adapter extracted and fully typed for create/find/update/delete across user, account, session, verification.
    • Where and query helpers are schema-aware and validate field/value pairs.
    • Kysely and memory adapters updated to be generic and infer table/field types.
    • Plugins: Admin/Additional Fields updated to typed schema; client InferPlugin and InferServerPlugin support schema generics.
    • Docs: New Convex integration page, sidebar entry, icon, and “Add to Cursor” MCP button; minor intro and database doc clarifications.
  • Migration

    • Define plugin/schema fields with field("string" | "number" | ... , { ... }) and satisfy AuthPluginSchema.
    • Update custom code to use generics: BetterAuthOptions, AuthContext, GenericEndpointContext, TransactionAdapter, Adapter.
    • Replace FieldAttribute with FieldAttributeFor where applicable; AdditionalUserFieldsInput now accepts <O, S>.
    • Update queries to use the new schema-aware Where type with valid field names and value types.
    • If using adapters directly, call memoryAdapter(db) or kyselyAdapter(db), and pass typed options.
    • No database changes required; migrations continue to generate as before.

🔄 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/5170 **Author:** [@R5dan](https://github.com/R5dan) **Created:** 10/8/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/better-types` --- ### 📝 Commits (10+) - [`1baaccb`](https://github.com/better-auth/better-auth/commit/1baaccbf52803d27046dce3da57c5c7201a020fb) docs: add Convex integration (#4785) - [`2dfdda7`](https://github.com/better-auth/better-auth/commit/2dfdda7ad8e07abe2850fec60aa0a7f5da59e46b) docs: add ai tooling - [`f6cbdcc`](https://github.com/better-auth/better-auth/commit/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b) chore: update chonkie url - [`65c2d5e`](https://github.com/better-auth/better-auth/commit/65c2d5ede29595c5239bf106f9b764dceac4e9e5) temp - [`dc78b7c`](https://github.com/better-auth/better-auth/commit/dc78b7c30ce51c87296f18bf1adc098d505d80dd) options - [`879b6e8`](https://github.com/better-auth/better-auth/commit/879b6e88683242951a40314fa8f8ab40e19d7f89) adapter - [`a19f978`](https://github.com/better-auth/better-auth/commit/a19f978ca72a54eb660c88de8b89398c519c2695) helpers - [`5808a93`](https://github.com/better-auth/better-auth/commit/5808a935b4cf6b82e754ec09c7b57f5a0587279b) types - [`2b51238`](https://github.com/better-auth/better-auth/commit/2b5123818263cbc6865d4beed7714958b8011408) feat: types - [`4972d22`](https://github.com/better-auth/better-auth/commit/4972d2258699632cd67280dd096d8a19e5acbec7) format ### 📊 Changes **59 files changed** (+2426 additions, -1137 deletions) <details> <summary>View changed files</summary> 📝 `.vscode/settings.json` (+1 -1) 📝 `docs/app/docs/[[...slug]]/page.tsx` (+2 -0) 📝 `docs/components/icons.tsx` (+23 -0) ➕ `docs/components/mdx/add-to-cursor.tsx` (+41 -0) 📝 `docs/components/sidebar-content.tsx` (+5 -0) 📝 `docs/content/docs/concepts/database.mdx` (+2 -1) ➕ `docs/content/docs/integrations/convex.mdx` (+347 -0) 📝 `docs/content/docs/introduction.mdx` (+48 -7) 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+106 -131) 📝 `packages/better-auth/src/adapters/adapter-factory/types.ts` (+62 -50) 📝 `packages/better-auth/src/adapters/kysely-adapter/dialect.ts` (+9 -6) 📝 `packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts` (+21 -11) 📝 `packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts` (+10 -6) 📝 `packages/better-auth/src/api/call.ts` (+42 -11) 📝 `packages/better-auth/src/api/index.ts` (+17 -14) 📝 `packages/better-auth/src/api/routes/session.ts` (+5 -1) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+6 -2) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+23 -18) 📝 `packages/better-auth/src/auth.ts` (+15 -12) 📝 `packages/better-auth/src/client/index.ts` (+10 -2) _...and 39 more files_ </details> ### 📄 Description This is a PR to add more type safety to Better Auth, specifically in regards to accessing and editing the database via endpoints and plugins. This PR got a lot bigger than I thought, hence why I have made the PR now, to get confirmation to keep going with this, help with some aspects and to make sure I am not misunderstanding certain types / functionality, and would appreciate any help given. Main Functionality: - Plugins now have there adapter types changed to include there own types - Hooks and middleware also have database changes - Database fields have typed values for config options such as `defaultValue` based on the field type provide I believe now that I have branched from the wrong branch, and am happy to migrate it to the correct one if needed. I also don't know why there are other commits as I am branching and merging to the same branch. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Introduces schema-aware generics across Better Auth to provide end-to-end type safety for adapters, APIs, hooks, and plugins. Adds a typed field builder, stronger model inference, and updates docs (Convex integration and Cursor MCP link). - **New Features** - Schema-aware generics: BetterAuthOptions<S>, AuthContext<S>, GenericEndpointContext<S>, TransactionAdapter<S>, and adapters now infer types from your AuthPluginSchema. - Typed fields via field(type, config): defaultValue and input/returned/required are now type-checked per field. - Internal adapter extracted and fully typed for create/find/update/delete across user, account, session, verification. - Where and query helpers are schema-aware and validate field/value pairs. - Kysely and memory adapters updated to be generic and infer table/field types. - Plugins: Admin/Additional Fields updated to typed schema; client InferPlugin and InferServerPlugin support schema generics. - Docs: New Convex integration page, sidebar entry, icon, and “Add to Cursor” MCP button; minor intro and database doc clarifications. - **Migration** - Define plugin/schema fields with field("string" | "number" | ... , { ... }) and satisfy AuthPluginSchema. - Update custom code to use generics: BetterAuthOptions<S>, AuthContext<S>, GenericEndpointContext<S>, TransactionAdapter<S>, Adapter<S>. - Replace FieldAttribute with FieldAttributeFor where applicable; AdditionalUserFieldsInput now accepts <O, S>. - Update queries to use the new schema-aware Where type with valid field names and value types. - If using adapters directly, call memoryAdapter<S>(db) or kyselyAdapter<S>(db), and pass typed options. - No database changes required; migrations continue to generate as before. <!-- 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-13 09:17: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#14068