[PR #6661] feat: add support for a custom betterAuth initializer that support intercepting and modifying the context #6809

Open
opened 2026-03-13 13:12:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6661
Author: @yacobmole
Created: 12/10/2025
Status: 🔄 Open

Base: canaryHead: feat/custom-initalizer


📝 Commits (3)

  • bca766f feat: allow custom auth context interceptor via new initializer
  • dcef062 chore: export type versions for custom
  • 073030f chore: lint & format

📊 Changes

3 files changed (+70 additions, -0 deletions)

View changed files

📝 packages/better-auth/package.json (+8 -0)
packages/better-auth/src/auth/custom.test.ts (+27 -0)
packages/better-auth/src/auth/custom.ts (+35 -0)

📄 Description

Summary

  • add a betterAuth initializer variant that allows intercepting and mutating the resolved auth context
  • expose the custom initializer through the package export map and cover the behavior with vitest
export const auth = betterAuth(
  {
    appName: "My App",
  },
  (ctx) => {
    ctx.appName = "My Better App";
    return ctx;
  },
);

Summary by cubic

Added a custom betterAuth initializer that lets you intercept and mutate the AuthContext after init. Exported as ./custom and covered by tests.

  • New Features
    • New ./custom entry: betterAuth(options, interceptor?) applies a context interceptor after init.
    • Validates interceptor and throws BetterAuthError if not a function.
    • Preserves Auth types and reflects mutations in auth.$context.

Written for commit 073030f90008e363ecffdb0feeafb2efeed02358. 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/6661 **Author:** [@yacobmole](https://github.com/yacobmole) **Created:** 12/10/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/custom-initalizer` --- ### 📝 Commits (3) - [`bca766f`](https://github.com/better-auth/better-auth/commit/bca766f5a293c8a39c68d10b5464c6b1ac272acb) feat: allow custom auth context interceptor via new initializer - [`dcef062`](https://github.com/better-auth/better-auth/commit/dcef062d298bd01642e895dec8cf66588386fb18) chore: export type versions for custom - [`073030f`](https://github.com/better-auth/better-auth/commit/073030f90008e363ecffdb0feeafb2efeed02358) chore: lint & format ### 📊 Changes **3 files changed** (+70 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/package.json` (+8 -0) ➕ `packages/better-auth/src/auth/custom.test.ts` (+27 -0) ➕ `packages/better-auth/src/auth/custom.ts` (+35 -0) </details> ### 📄 Description Summary - add a `betterAuth` initializer variant that allows intercepting and mutating the resolved auth context - expose the custom initializer through the package export map and cover the behavior with vitest ```ts export const auth = betterAuth( { appName: "My App", }, (ctx) => { ctx.appName = "My Better App"; return ctx; }, ); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added a custom betterAuth initializer that lets you intercept and mutate the AuthContext after init. Exported as ./custom and covered by tests. - **New Features** - New ./custom entry: betterAuth(options, interceptor?) applies a context interceptor after init. - Validates interceptor and throws BetterAuthError if not a function. - Preserves Auth types and reflects mutations in auth.$context. <sup>Written for commit 073030f90008e363ecffdb0feeafb2efeed02358. 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 13:12:30 -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#6809