[PR #7514] [MERGED] refactor: generic in BetterAuthPluginRegistry #24269

Closed
opened 2026-04-15 22:16:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7514
Author: @himself65
Created: 1/21/2026
Status: Merged
Merged: 1/22/2026
Merged by: @himself65

Base: canaryHead: himself65/2026/01/20/improve


📝 Commits (8)

📊 Changes

42 files changed (+191 additions, -82 deletions)

View changed files

📝 packages/better-auth/src/context/create-context.ts (+1 -1)
📝 packages/better-auth/src/plugins/admin/admin.ts (+2 -2)
📝 packages/better-auth/src/plugins/anonymous/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/api-key/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/bearer/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/captcha/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/device-authorization/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+1 -1)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/haveibeenpwned/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/jwt/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/last-login-method/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/magic-link/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/mcp/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/multi-session/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+2 -2)
📝 packages/better-auth/src/plugins/one-tap/index.ts (+2 -2)

...and 22 more files

📄 Description

Summary by cubic

Refactored BetterAuthPluginRegistry to use separate generics for AuthOptions and per-plugin Options, and tightened typing for plugin lookup and context. This improves type inference for getPlugin/hasPlugin and aligns AuthContext with configured options.

  • Refactors
    • Replaced BetterAuthPluginRegistry<Auth, Context> with BetterAuthPluginRegistry<AuthOptions, Options> across all plugins.
    • Made PluginContext and AuthContext generic on Options; Auth.$context is now Promise<AuthContext>.
    • getPlugin now returns types keyed by the registry using inferred plugin options; hasPlugin is strongly typed (true) for known plugin IDs.
    • Added UnionToIntersection helper and InferPluginIDs utility to derive plugin ID intersections.

Written for commit 0b6cb3b744. Summary will update on new commits.


���� 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/7514 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/21/2026 **Status:** ✅ Merged **Merged:** 1/22/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2026/01/20/improve` --- ### 📝 Commits (8) - [`db2f8cc`](https://github.com/better-auth/better-auth/commit/db2f8cc8e58540aac268b0cdd2085de6b95aa61a) refactor: generic in `BetterAuthPluginRegistry` - [`a1c3964`](https://github.com/better-auth/better-auth/commit/a1c3964c60fd68a22c6d4188ff45a70da0668f50) test: add - [`265ac9d`](https://github.com/better-auth/better-auth/commit/265ac9dc94fb540b96422240b1e23904503109ba) test: update - [`bca1ed9`](https://github.com/better-auth/better-auth/commit/bca1ed9fbf8bbe3ddc6470af3f6e4d2d7dd2270c) chore: comment update - [`d51fdbc`](https://github.com/better-auth/better-auth/commit/d51fdbc714e3fca76b732c393a6bed7c1f34ef75) chore: litn - [`184fa21`](https://github.com/better-auth/better-auth/commit/184fa2169035a7559aef004db1f8ee1be0d25f21) chore: lint - [`d8a4316`](https://github.com/better-auth/better-auth/commit/d8a4316e69263fe590f7f5c16e43efc8d3666a90) chore: space - [`0b6cb3b`](https://github.com/better-auth/better-auth/commit/0b6cb3b744fafa8298eeceaa554d4eb3c92c0f7c) chore: example ### 📊 Changes **42 files changed** (+191 additions, -82 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/context/create-context.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/anonymous/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/api-key/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/bearer/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/captcha/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/device-authorization/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/haveibeenpwned/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/jwt/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/last-login-method/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/magic-link/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/mcp/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/multi-session/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/one-tap/index.ts` (+2 -2) _...and 22 more files_ </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Refactored BetterAuthPluginRegistry to use separate generics for AuthOptions and per-plugin Options, and tightened typing for plugin lookup and context. This improves type inference for getPlugin/hasPlugin and aligns AuthContext with configured options. - **Refactors** - Replaced BetterAuthPluginRegistry<Auth, Context> with BetterAuthPluginRegistry<AuthOptions, Options> across all plugins. - Made PluginContext and AuthContext generic on Options; Auth.$context is now Promise<AuthContext<Options>>. - getPlugin now returns types keyed by the registry using inferred plugin options; hasPlugin is strongly typed (true) for known plugin IDs. - Added UnionToIntersection helper and InferPluginIDs utility to derive plugin ID intersections. <sup>Written for commit 0b6cb3b744fafa8298eeceaa554d4eb3c92c0f7c. Summary will update on new commits.</sup> <!-- 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 22:16:26 -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#24269