[PR #5888] [MERGED] feat: support pass raw function as middleware #6298

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5888
Author: @himself65
Created: 11/10/2025
Status: Merged
Merged: 11/13/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/11/10/middleware


📝 Commits (2)

  • 0a6f518 feat: support pass raw function as middleware
  • f053400 fix: type

📊 Changes

5 files changed (+41 additions, -73 deletions)

View changed files

📝 packages/better-auth/src/api/to-auth-endpoints.ts (+23 -3)
📝 packages/better-auth/src/plugins/index.ts (+0 -1)
📝 packages/better-auth/src/utils/shim.ts (+0 -60)
📝 packages/core/src/types/index.ts (+5 -1)
📝 packages/core/src/types/plugin.ts (+13 -8)

📄 Description

Summary by cubic

Support passing raw functions as middleware in plugin hooks, reducing boilerplate and making plugins easier to write. Raw functions are auto-wrapped with createAuthMiddleware and a default matcher.

  • New Features

    • Plugin hooks (before/after) accept either {matcher, handler} or a raw middleware function.
    • Raw functions are wrapped with createAuthMiddleware and use a matcher that always returns true.
  • Refactors

    • optionsMiddleware is no longer re-exported from better-auth.
    • Removed the unused shimEndpoint helper.

Written for commit f053400d86. Summary will update automatically 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/5888 **Author:** [@himself65](https://github.com/himself65) **Created:** 11/10/2025 **Status:** ✅ Merged **Merged:** 11/13/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/11/10/middleware` --- ### 📝 Commits (2) - [`0a6f518`](https://github.com/better-auth/better-auth/commit/0a6f518b31b9ab6daf420540e74b2cbb1ceb07b8) feat: support pass raw function as middleware - [`f053400`](https://github.com/better-auth/better-auth/commit/f053400d8637916be15383e91d90896d0c39f0d9) fix: type ### 📊 Changes **5 files changed** (+41 additions, -73 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+23 -3) 📝 `packages/better-auth/src/plugins/index.ts` (+0 -1) 📝 `packages/better-auth/src/utils/shim.ts` (+0 -60) 📝 `packages/core/src/types/index.ts` (+5 -1) 📝 `packages/core/src/types/plugin.ts` (+13 -8) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Support passing raw functions as middleware in plugin hooks, reducing boilerplate and making plugins easier to write. Raw functions are auto-wrapped with createAuthMiddleware and a default matcher. - **New Features** - Plugin hooks (before/after) accept either {matcher, handler} or a raw middleware function. - Raw functions are wrapped with createAuthMiddleware and use a matcher that always returns true. - **Refactors** - optionsMiddleware is no longer re-exported from better-auth. - Removed the unused shimEndpoint helper. <sup>Written for commit f053400d8637916be15383e91d90896d0c39f0d9. Summary will update automatically 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-03-13 12:53:55 -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#6298