[PR #4792] [MERGED] feat(db): delete hooks #22480

Closed
opened 2026-04-15 21:04:39 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4792
Author: @Kinfe123
Created: 9/20/2025
Status: Merged
Merged: 9/23/2025
Merged by: @himself65

Base: canaryHead: feat/delete-hooks


📝 Commits (7)

📊 Changes

6 files changed (+400 additions, -25 deletions)

View changed files

📝 docs/content/docs/concepts/database.mdx (+28 -1)
📝 packages/better-auth/src/api/routes/update-user.ts (+5 -5)
📝 packages/better-auth/src/db/db.test.ts (+144 -1)
📝 packages/better-auth/src/db/internal-adapter.ts (+38 -18)
📝 packages/better-auth/src/db/with-hooks.ts (+117 -0)
📝 packages/better-auth/src/types/options.ts (+68 -0)

📄 Description

Fixes: https://github.com/better-auth/better-auth/issues/4766

Summary by cubic

Add database delete hooks (before/after) for user, session, account, and verification. All delete paths now run through hooks, allowing deletions to be aborted and letting you run side effects with access to the endpoint context.

  • New Features

    • Added databaseHooks..delete.before/after with entity payload and optional context.
    • before can return false to cancel deletion; after runs post-delete.
    • Docs updated with user/session examples; tests cover success and abort flows.
  • Refactors

    • Introduced deleteWithHooks and deleteManyWithHooks and wired them into internalAdapter.
    • Updated delete user/session/verification flows to pass context and trigger hooks.

🔄 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/4792 **Author:** [@Kinfe123](https://github.com/Kinfe123) **Created:** 9/20/2025 **Status:** ✅ Merged **Merged:** 9/23/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `feat/delete-hooks` --- ### 📝 Commits (7) - [`69e7588`](https://github.com/better-auth/better-auth/commit/69e7588fbd403608113fc150eb7bf70ad94a59df) feat: db delete hook - [`2ca15e0`](https://github.com/better-auth/better-auth/commit/2ca15e0c7783cd5e81b9fd163885fd2f7a033c36) update - [`f102c05`](https://github.com/better-auth/better-auth/commit/f102c0529dd9590259b795352b11d51b1f64b765) docs - [`add0069`](https://github.com/better-auth/better-auth/commit/add0069af2127e6e7bba88490e57f3f5bbbd5fa3) docs update - [`67288e1`](https://github.com/better-auth/better-auth/commit/67288e115361854eb520aeac0879e37e1619b512) docs - [`b590e1e`](https://github.com/better-auth/better-auth/commit/b590e1e86f3bad9e67cb5fdd5297c64a991162db) Merge branch 'canary' into feat/delete-hooks - [`9cb1aa1`](https://github.com/better-auth/better-auth/commit/9cb1aa1c02408897216d321329ee826462c31aea) Merge branch 'canary' into feat/delete-hooks ### 📊 Changes **6 files changed** (+400 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/database.mdx` (+28 -1) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+5 -5) 📝 `packages/better-auth/src/db/db.test.ts` (+144 -1) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+38 -18) 📝 `packages/better-auth/src/db/with-hooks.ts` (+117 -0) 📝 `packages/better-auth/src/types/options.ts` (+68 -0) </details> ### 📄 Description Fixes: https://github.com/better-auth/better-auth/issues/4766 <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Add database delete hooks (before/after) for user, session, account, and verification. All delete paths now run through hooks, allowing deletions to be aborted and letting you run side effects with access to the endpoint context. - New Features - Added databaseHooks.<model>.delete.before/after with entity payload and optional context. - before can return false to cancel deletion; after runs post-delete. - Docs updated with user/session examples; tests cover success and abort flows. - Refactors - Introduced deleteWithHooks and deleteManyWithHooks and wired them into internalAdapter. - Updated delete user/session/verification flows to pass context and trigger hooks. <!-- 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 21:04:39 -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#22480