[PR #5720] feat(api-key): add create, update and delete hooks #14424

Closed
opened 2026-04-13 09:28:05 -05:00 by GiteaMirror · 0 comments
Owner

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

State: closed
Merged: No


Description

Adds lifecycle hooks (create, update, delete) for the API Key plugin.

Closes #5694

Changes

  • Added before/after hooks for create, update, and delete operations
  • Added tests for all hook scenarios
  • Updated documentation with hook examples

Summary by cubic

Adds before/after lifecycle hooks to the API Key plugin for create, update, and delete so you can validate, modify, or block these actions. Also updates docs, tests, and adds a new error code for hook failures.

  • New Features
    • Hooks: before can return false to cancel, or { data } to modify; hooks receive parsed metadata/permissions and values are serialized automatically; after runs with the created/updated/deleted record.
    • Errors: adds BEFORE_HOOK_FAILED; returns BAD_REQUEST when a before hook cancels create, update, or delete.
    • Docs and tests: extensive examples and coverage for all hook paths.

Written for commit 4c02248a63. Summary will update automatically on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5720 **State:** closed **Merged:** No --- ## Description Adds lifecycle hooks (create, update, delete) for the API Key plugin. Closes #5694 ## Changes - Added before/after hooks for create, update, and delete operations - Added tests for all hook scenarios - Updated documentation with hook examples <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds before/after lifecycle hooks to the API Key plugin for create, update, and delete so you can validate, modify, or block these actions. Also updates docs, tests, and adds a new error code for hook failures. - **New Features** - Hooks: before can return false to cancel, or { data } to modify; hooks receive parsed metadata/permissions and values are serialized automatically; after runs with the created/updated/deleted record. - Errors: adds BEFORE_HOOK_FAILED; returns BAD_REQUEST when a before hook cancels create, update, or delete. - Docs and tests: extensive examples and coverage for all hook paths. <sup>Written for commit 4c02248a63ccf9ebca76adc25bf5f14a8fcd8da8. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:28:05 -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#14424