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

Open
opened 2026-04-17 23:13:53 -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: mainHead: feat/custom-initalizer


📝 Commits (3)

  • 5252a91 feat: allow custom auth context interceptor via new initializer
  • 4cf4f76 chore: export type versions for custom
  • 862bba4 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 to intercept and mutate the AuthContext after init. 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.
    • Adds typesVersions for ./custom; preserves Auth types and reflects mutations in auth.$context.

Written for commit 862bba4c65. 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/6661 **Author:** [@yacobmole](https://github.com/yacobmole) **Created:** 12/10/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/custom-initalizer` --- ### 📝 Commits (3) - [`5252a91`](https://github.com/better-auth/better-auth/commit/5252a911a6ab1e5b550eafcd99d284e85e7574fc) feat: allow custom auth context interceptor via new initializer - [`4cf4f76`](https://github.com/better-auth/better-auth/commit/4cf4f768e9936b01a1fdc1f70ea868330b2be909) chore: export type versions for custom - [`862bba4`](https://github.com/better-auth/better-auth/commit/862bba4c652e11e3ca8cfebcb40da8dd4fb4b756) 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 to intercept and mutate the `AuthContext` after init. 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. - Adds `typesVersions` for `./custom`; preserves `Auth` types and reflects mutations in `auth.$context`. <sup>Written for commit 862bba4c652e11e3ca8cfebcb40da8dd4fb4b756. 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-17 23:13:53 -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#32410