[PR #7250] [CLOSED] Refactor: Move runWithEndpointContext to top-level wrapper #7173

Closed
opened 2026-03-13 13:26:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7250
Author: @Ridhim-RR
Created: 1/10/2026
Status: Closed

Base: canaryHead: call-runWithEndpointContext-top-level


📝 Commits (10+)

📊 Changes

3 files changed (+38 additions, -11 deletions)

View changed files

📝 docs/content/docs/plugins/have-i-been-pwned.mdx (+2 -1)
📝 packages/better-auth/src/plugins/haveibeenpwned/index.ts (+27 -6)
📝 packages/core/src/api/index.ts (+9 -4)

📄 Description

Description

This PR refactors the endpoint handler logic to improve readability and maintainability. Previously, runWithEndpointContext was being called inline for every endpoint definition, leading to code duplication.

I have introduced a withEndpointContext helper function that wraps handlers consistently. This ensures all endpoints benefit from the same context injection logic without cluttering the route definitions.

Changes
Added withEndpointContext: A reusable higher-order function that handles the runWithEndpointContext boilerplate.

/**
 * Higher-Order Function to wrap handlers with the necessary endpoint context.
 * This removes the need to manually call runWithEndpointContext inside every handler.
 */
const withEndpointContext = (handler: Handler) => {
  return async (ctx: any) => {
    return runWithEndpointContext(ctx as any, () => handler(ctx));
  };
};

// Usage is now clean and uniform
return createEndpoint(path, options, withEndpointContext(handler));

Summary by cubic

Moved runWithEndpointContext into a reusable withEndpointContext wrapper to remove inline duplication and simplify endpoint setup. Also added async custom message support to the Have I Been Pwned plugin and cleaned up the docs example.

  • Refactors

    • Added withEndpointContext(handler) to wrap handlers with runWithEndpointContext.
    • Replaced inline calls in createAuthEndpoint for cleaner, consistent route definitions.
  • New Features

    • Have I Been Pwned: supports async customPasswordCompromisedMessage via a function returning Promise; introduced extractCustomMessage with logging and updated error handling.
    • Docs: clarified static message example and minor formatting.

Written for commit abd89327b8. 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/7250 **Author:** [@Ridhim-RR](https://github.com/Ridhim-RR) **Created:** 1/10/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `call-runWithEndpointContext-top-level` --- ### 📝 Commits (10+) - [`6afd4dd`](https://github.com/better-auth/better-auth/commit/6afd4dd77a71a3b27262a5193b256b9167ceac11) fix(Passkey):delete-challenge - [`034f757`](https://github.com/better-auth/better-auth/commit/034f757adc245f05e20f1e79eaf72c596f5191b1) fix: test case - [`b5b22f3`](https://github.com/better-auth/better-auth/commit/b5b22f3e464161df51286113bf16d5ee92782eb0) Merge branch 'canary' into fix/passkey/delete-challenge - [`4a50afa`](https://github.com/better-auth/better-auth/commit/4a50afa365e1900b6429c814856eb6ccaa4d361e) chore: lint issue - [`93187d7`](https://github.com/better-auth/better-auth/commit/93187d726e1950789e5aacaa48777a2fc2578b78) Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into fix/passkey/delete-challenge - [`642db75`](https://github.com/better-auth/better-auth/commit/642db75b743607ced6b2c995d1f836ee348db5a3) Merge branch 'fix/passkey/delete-challenge' of https://github.com/Ridhim-RR/better-auth into fix/passkey/delete-challenge - [`5c82651`](https://github.com/better-auth/better-auth/commit/5c826511d6ad7d4c0bbdc5c2b2edb15a5e6f911d) Merge branch 'canary' of https://github.com/Ridhim-RR/better-auth into feat/haveibeenpwned/support-async-custom-message - [`f6e5626`](https://github.com/better-auth/better-auth/commit/f6e5626fc0096b5a85e435aaa142047f34a57baa) feat(haveIBeenPwned):support async custom message - [`e8488a2`](https://github.com/better-auth/better-auth/commit/e8488a2f8b7257b6d32e72d09f7c0e7c0b2b7b08) chore: linitng issue resolved - [`b1c7ae6`](https://github.com/better-auth/better-auth/commit/b1c7ae6516ed4642a06fee00b4a469910f69fe4d) Update docs/content/docs/plugins/have-i-been-pwned.mdx ### 📊 Changes **3 files changed** (+38 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/have-i-been-pwned.mdx` (+2 -1) 📝 `packages/better-auth/src/plugins/haveibeenpwned/index.ts` (+27 -6) 📝 `packages/core/src/api/index.ts` (+9 -4) </details> ### 📄 Description **Description** This PR refactors the endpoint handler logic to improve readability and maintainability. Previously, runWithEndpointContext was being called inline for every endpoint definition, leading to code duplication. I have introduced a withEndpointContext helper function that wraps handlers consistently. This ensures all endpoints benefit from the same context injection logic without cluttering the route definitions. **Changes** Added withEndpointContext: A reusable higher-order function that handles the runWithEndpointContext boilerplate. ``` /** * Higher-Order Function to wrap handlers with the necessary endpoint context. * This removes the need to manually call runWithEndpointContext inside every handler. */ const withEndpointContext = (handler: Handler) => { return async (ctx: any) => { return runWithEndpointContext(ctx as any, () => handler(ctx)); }; }; // Usage is now clean and uniform return createEndpoint(path, options, withEndpointContext(handler)); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Moved runWithEndpointContext into a reusable withEndpointContext wrapper to remove inline duplication and simplify endpoint setup. Also added async custom message support to the Have I Been Pwned plugin and cleaned up the docs example. - **Refactors** - Added withEndpointContext(handler) to wrap handlers with runWithEndpointContext. - Replaced inline calls in createAuthEndpoint for cleaner, consistent route definitions. - **New Features** - Have I Been Pwned: supports async customPasswordCompromisedMessage via a function returning Promise<string>; introduced extractCustomMessage with logging and updated error handling. - Docs: clarified static message example and minor formatting. <sup>Written for commit abd89327b82b0f656a0c60c95b8abc8be5c84b6d. 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-03-13 13:26:40 -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#7173