[PR #8792] docs(hooks): add example for handling multiple endpoints in a single hook #16462

Open
opened 2026-04-13 10:31:55 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8792

State: open
Merged: No


Summary

  • Adds a new example showing how to handle multiple endpoints within a single before or after hook using ctx.path conditionals
  • Adds a callout clarifying that hooks take a single middleware function, not an array

Context

Users frequently ask how to set multiple handlers in hooks (e.g., Discussion #8723). The current docs only show single-endpoint examples, which leads to confusion about whether hooks accept an array of handlers.

This small addition makes it clear that you branch on ctx.path inside one middleware function.


Summary by cubic

Add a docs example showing how to handle multiple endpoints in a single hook by branching on ctx.path inside one createAuthMiddleware for before/after. Add a callout clarifying that hooks accept a single middleware function, not an array.

Written for commit c51e8a3d89. Summary will update on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8792 **State:** open **Merged:** No --- ## Summary - Adds a new example showing how to handle multiple endpoints within a single `before` or `after` hook using `ctx.path` conditionals - Adds a callout clarifying that hooks take a single middleware function, not an array ## Context Users frequently ask how to set multiple handlers in hooks (e.g., [Discussion #8723](https://github.com/better-auth/better-auth/discussions/8723#discussioncomment-16331341)). The current docs only show single-endpoint examples, which leads to confusion about whether hooks accept an array of handlers. This small addition makes it clear that you branch on `ctx.path` inside one middleware function. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a docs example showing how to handle multiple endpoints in a single hook by branching on `ctx.path` inside one `createAuthMiddleware` for `before`/`after`. Add a callout clarifying that hooks accept a single middleware function, not an array. <sup>Written for commit c51e8a3d89b1b74ff0ffacaf2489b64f7eb37b1a. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 10:31: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#16462