[PR #8912] fix(core): expose plugin init-contributed options via getPlugin() #16538

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8912
Author: @sleepe229
Created: 4/2/2026
Status: 🔄 Open

Base: main ← Head: fix/plugin-options-accessible-via-get-plugin


📝 Commits (3)

  • f919016 fix(core): declare inherited APIError properties to fix TypeScript type resolution
  • 7ac5910 fix(core): expose plugin init-contributed options
  • 243cfea fix(core): deep-merge plugin init options into plugin.options via defu

📊 Changes

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

View changed files

📝 packages/better-auth/src/context/create-context.test.ts (+74 -0)
📝 packages/better-auth/src/context/helpers.ts (+8 -0)
📝 packages/core/src/error/index.ts (+8 -0)

📄 Description

Summary

  • getPlugin(id) previously returned the original plugin definition object, causing plugin.options to be undefined for plugins that contribute options via init()
    rather than setting them directly on the definition
  • In runPluginInit, after merging init()-returned options into context.options via defu, they are now also merged back onto plugin.options
  • Plugin-defined options take precedence over init()-contributed ones ({ ...restOpts, ...plugin.options })

Test plan

  • New tests in create-context.test.ts verify that getPlugin(id)?.options reflects values contributed via init()
  • Existing tests verify that plugin-defined options still take precedence
  • Run vitest packages/better-auth/src/context/create-context.test.ts to confirm

Fixes #8908


Summary by cubic

Expose init-contributed plugin options via getPlugin(id)?.options so consumers see the effective configuration. Also fix APIError typings to surface inherited fields in TypeScript. Fixes #8908.

  • Bug Fixes
    • In better-auth, deep-merge init()-returned options back into plugin.options with defu in runPluginInit; preserves nested keys and keeps plugin-defined options as the source of truth. Tests cover getPlugin() access, nested merge, and precedence.
    • In core, declare inherited APIError properties (status, body, headers, statusCode, message) to fix TypeScript type resolution.

Written for commit 243cfea096. 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/8912 **Author:** [@sleepe229](https://github.com/sleepe229) **Created:** 4/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/plugin-options-accessible-via-get-plugin` --- ### 📝 Commits (3) - [`f919016`](https://github.com/better-auth/better-auth/commit/f91901640c93650cb28edf22af0b150d345af62f) fix(core): declare inherited APIError properties to fix TypeScript type resolution - [`7ac5910`](https://github.com/better-auth/better-auth/commit/7ac59101a592cb72623cb138dbda794f445bad91) fix(core): expose plugin init-contributed options - [`243cfea`](https://github.com/better-auth/better-auth/commit/243cfea09622719385cba121bde2c7ad4d46c7f0) fix(core): deep-merge plugin init options into plugin.options via defu ### 📊 Changes **3 files changed** (+90 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/context/create-context.test.ts` (+74 -0) 📝 `packages/better-auth/src/context/helpers.ts` (+8 -0) 📝 `packages/core/src/error/index.ts` (+8 -0) </details> ### 📄 Description ## Summary - `getPlugin(id)` previously returned the original plugin definition object, causing `plugin.options` to be `undefined` for plugins that contribute options via `init()` rather than setting them directly on the definition - In `runPluginInit`, after merging `init()`-returned options into `context.options` via `defu`, they are now also merged back onto `plugin.options` - Plugin-defined `options` take precedence over `init()`-contributed ones (`{ ...restOpts, ...plugin.options }`) ## Test plan - [ ] New tests in `create-context.test.ts` verify that `getPlugin(id)?.options` reflects values contributed via `init()` - [ ] Existing tests verify that plugin-defined options still take precedence - [ ] Run `vitest packages/better-auth/src/context/create-context.test.ts` to confirm Fixes #8908 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Expose init-contributed plugin options via `getPlugin(id)?.options` so consumers see the effective configuration. Also fix `APIError` typings to surface inherited fields in TypeScript. Fixes #8908. - **Bug Fixes** - In `better-auth`, deep-merge `init()`-returned options back into `plugin.options` with `defu` in `runPluginInit`; preserves nested keys and keeps plugin-defined options as the source of truth. Tests cover `getPlugin()` access, nested merge, and precedence. - In `core`, declare inherited `APIError` properties (`status`, `body`, `headers`, `statusCode`, `message`) to fix TypeScript type resolution. <sup>Written for commit 243cfea09622719385cba121bde2c7ad4d46c7f0. 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-13 10:33: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#16538