[PR #8336] feat(api-key): support additional fields in api key schema - Take 2 #24807

Open
opened 2026-04-15 22:34:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8336
Author: @thomasmol
Created: 3/3/2026
Status: 🔄 Open

Base: nextHead: feat/allow-additional-fields-for-api-key-plugin


📝 Commits (10+)

  • ff58fcd init
  • 6fec43d .
  • 4dc257e Update api-key.mdx
  • 437f204 Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • 3302e97 Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • 0364002 Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • 51131f2 Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • b0a1a9a Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • 317e0a2 Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin
  • c2b0eae Revert test

📊 Changes

12 files changed (+444 additions, -48 deletions)

View changed files

📝 docs/content/docs/plugins/api-key/reference.mdx (+19 -2)
📝 packages/api-key/src/api-key.test.ts (+234 -1)
📝 packages/api-key/src/client.ts (+20 -3)
📝 packages/api-key/src/index.ts (+55 -13)
📝 packages/api-key/src/routes/create-api-key.ts (+25 -5)
📝 packages/api-key/src/routes/get-api-key.ts (+3 -3)
📝 packages/api-key/src/routes/index.ts (+31 -8)
📝 packages/api-key/src/routes/list-api-keys.ts (+3 -3)
📝 packages/api-key/src/routes/update-api-key.ts (+28 -5)
📝 packages/api-key/src/routes/verify-api-key.ts (+3 -3)
📝 packages/api-key/src/schema.ts (+7 -1)
📝 packages/api-key/src/types.ts (+16 -1)

📄 Description

  • add apikey.additionalFields to api‑key schema options
  • accept/persist extra fields in create/update endpoints
  • document schema extension usage for api keys

Closes #7724


Summary by cubic

Add support for custom fields on API keys via apikey.additionalFields; all endpoints now accept/return these fields with validation and strong typing. apiKeyClient now accepts a schema option to infer request/response types for additional fields. Closes #7724.

  • New Features
    • Added apikey.additionalFields to define extra DB columns and input visibility.
    • Extended create/update to accept and persist extra fields; required fields enforced; partial updates allowed.
    • input: false fields are stripped from requests and not persisted.
    • Responses from get/list/verify include extra fields; types inferred via ApiKeySchema/InferApiKey; apiKeyClient can take schema for client-side type inference.
    • Docs updated with an example; tests cover required/optional behavior, input:false handling, and type inference.

Written for commit ffbd07d9d5. 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/8336 **Author:** [@thomasmol](https://github.com/thomasmol) **Created:** 3/3/2026 **Status:** 🔄 Open **Base:** `next` ← **Head:** `feat/allow-additional-fields-for-api-key-plugin` --- ### 📝 Commits (10+) - [`ff58fcd`](https://github.com/better-auth/better-auth/commit/ff58fcd8edb6e9a3838aead6ffde80f26f3ffb3f) init - [`6fec43d`](https://github.com/better-auth/better-auth/commit/6fec43dc7b1b49442260d91c58d7f79040afea6e) . - [`4dc257e`](https://github.com/better-auth/better-auth/commit/4dc257e73b2a2c30a2b9532c7cbdf263500c7b7d) Update api-key.mdx - [`437f204`](https://github.com/better-auth/better-auth/commit/437f204443893c3d2990f9a6a35a518f81cb18f7) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`3302e97`](https://github.com/better-auth/better-auth/commit/3302e971a79eb215e24dd43458b5f1f31caf9f99) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`0364002`](https://github.com/better-auth/better-auth/commit/0364002dbb9502e86a6f75bb27d6529c4c04e526) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`51131f2`](https://github.com/better-auth/better-auth/commit/51131f290d6c2f16a058379158f8d58d8558e02c) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`b0a1a9a`](https://github.com/better-auth/better-auth/commit/b0a1a9a714aed16f36e49f192dd633d79e37772e) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`317e0a2`](https://github.com/better-auth/better-auth/commit/317e0a224a24d4e457894f42194b5366d163ed0a) Merge branch 'canary' into feat/allow-additional-fields-for-api-key-plugin - [`c2b0eae`](https://github.com/better-auth/better-auth/commit/c2b0eae3a728111ee8adcf1b7a76196f3343cab3) Revert test ### 📊 Changes **12 files changed** (+444 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/api-key/reference.mdx` (+19 -2) 📝 `packages/api-key/src/api-key.test.ts` (+234 -1) 📝 `packages/api-key/src/client.ts` (+20 -3) 📝 `packages/api-key/src/index.ts` (+55 -13) 📝 `packages/api-key/src/routes/create-api-key.ts` (+25 -5) 📝 `packages/api-key/src/routes/get-api-key.ts` (+3 -3) 📝 `packages/api-key/src/routes/index.ts` (+31 -8) 📝 `packages/api-key/src/routes/list-api-keys.ts` (+3 -3) 📝 `packages/api-key/src/routes/update-api-key.ts` (+28 -5) 📝 `packages/api-key/src/routes/verify-api-key.ts` (+3 -3) 📝 `packages/api-key/src/schema.ts` (+7 -1) 📝 `packages/api-key/src/types.ts` (+16 -1) </details> ### 📄 Description - add `apikey.additionalFields` to api‑key schema options - accept/persist extra fields in create/update endpoints - document schema extension usage for api keys Closes #7724 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add support for custom fields on API keys via apikey.additionalFields; all endpoints now accept/return these fields with validation and strong typing. apiKeyClient now accepts a schema option to infer request/response types for additional fields. Closes #7724. - **New Features** - Added apikey.additionalFields to define extra DB columns and input visibility. - Extended create/update to accept and persist extra fields; required fields enforced; partial updates allowed. - input: false fields are stripped from requests and not persisted. - Responses from get/list/verify include extra fields; types inferred via ApiKeySchema/InferApiKey; apiKeyClient can take schema for client-side type inference. - Docs updated with an example; tests cover required/optional behavior, input:false handling, and type inference. <sup>Written for commit ffbd07d9d5d323a727592711ab8de9829bc1c3f6. 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-15 22:34:09 -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#24807