[PR #4836] [CLOSED] Feat/database hooks delete #13852

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4836
Author: @nehaaprasad
Created: 9/23/2025
Status: Closed

Base: canaryHead: feat/database-hooks-delete


📝 Commits (5)

  • 4b79b78 feat: Add plugin interface fields for Payload CMS integration
  • 3393166 feat: Implement plugin initialization and lifecycle management
  • bc9585c feat: Add delete hooks to database hooks configuration
  • d07902d feat: Implement delete hooks functionality
  • 0c1e605 feat: add delete hooks to database operations

📊 Changes

5 files changed (+160 additions, -45 deletions)

View changed files

📝 packages/better-auth/src/db/internal-adapter.ts (+37 -37)
📝 packages/better-auth/src/db/with-hooks.ts (+77 -0)
📝 packages/better-auth/src/init.ts (+6 -4)
📝 packages/better-auth/src/types/options.ts (+40 -0)
📝 packages/better-auth/src/types/plugins.ts (+0 -4)

📄 Description

Summary

  • Adds delete hooks support to Better Auth database operations, enabling plugins and applications to intercept and customize delete operations.

Changes

  • Database Hooks: Added delete hooks to BetterAuthOptions["databaseHooks"] for user, session, account, and verification models
  • Hook Implementation: Created deleteWithHooks and deleteManyWithHooks functions in with-hooks.ts
  • Internal Adapter: Updated all delete operations in internal-adapter.ts to use the new hook system

Features

  • Before Hooks: Execute custom logic before deletion (can prevent deletion by returning false)
  • After Hooks: Execute cleanup logic after successful deletion
  • Consistent API: Same pattern as existing create/update hooks
  • Type Safety: Full TypeScript support with proper typing

Use Cases

  • Plugin cleanup when users are deleted
  • Audit logging for delete operations
  • Data validation before deletion
  • External system synchronization

Breaking Changes

None - this is purely additive functionality.


Summary by cubic

Adds delete hooks to all database models and routes all delete operations through the new hook layer. This lets plugins and apps intercept, veto, and react to deletions for cleanup, auditing, and sync.

  • New Features
    • Delete hooks in BetterAuthOptions for user, session, account, and verification.
    • Before/after hooks; before can return false to prevent deletion.
    • deleteWithHooks and deleteManyWithHooks helpers in with-hooks.ts.
    • Internal adapter updated to use hook-based deletes across the codebase.
    • Full TypeScript typing for the new 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/4836 **Author:** [@nehaaprasad](https://github.com/nehaaprasad) **Created:** 9/23/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/database-hooks-delete` --- ### 📝 Commits (5) - [`4b79b78`](https://github.com/better-auth/better-auth/commit/4b79b785dc1a12c6d8b237be32d032fa15221aa6) feat: Add plugin interface fields for Payload CMS integration - [`3393166`](https://github.com/better-auth/better-auth/commit/3393166f21d553ca2fd05524b6721e33264381cf) feat: Implement plugin initialization and lifecycle management - [`bc9585c`](https://github.com/better-auth/better-auth/commit/bc9585ca7777886279518c27292cca9ff820ad28) feat: Add delete hooks to database hooks configuration - [`d07902d`](https://github.com/better-auth/better-auth/commit/d07902d3d048ba5afcdf4cda30941f476b3ddcc9) feat: Implement delete hooks functionality - [`0c1e605`](https://github.com/better-auth/better-auth/commit/0c1e60553f7b29910b90effee3796b10e23036db) feat: add delete hooks to database operations ### 📊 Changes **5 files changed** (+160 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/internal-adapter.ts` (+37 -37) 📝 `packages/better-auth/src/db/with-hooks.ts` (+77 -0) 📝 `packages/better-auth/src/init.ts` (+6 -4) 📝 `packages/better-auth/src/types/options.ts` (+40 -0) 📝 `packages/better-auth/src/types/plugins.ts` (+0 -4) </details> ### 📄 Description ### Summary - Adds delete hooks support to Better Auth database operations, enabling plugins and applications to intercept and customize delete operations. ### Changes - **Database Hooks**: Added `delete` hooks to `BetterAuthOptions["databaseHooks"]` for user, session, account, and verification models - **Hook Implementation**: Created `deleteWithHooks` and `deleteManyWithHooks` functions in `with-hooks.ts` - **Internal Adapter**: Updated all delete operations in `internal-adapter.ts` to use the new hook system ## Features - **Before Hooks**: Execute custom logic before deletion (can prevent deletion by returning `false`) - **After Hooks**: Execute cleanup logic after successful deletion - **Consistent API**: Same pattern as existing create/update hooks - **Type Safety**: Full TypeScript support with proper typing ## Use Cases - Plugin cleanup when users are deleted - Audit logging for delete operations - Data validation before deletion - External system synchronization ## Breaking Changes None - this is purely additive functionality. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds delete hooks to all database models and routes all delete operations through the new hook layer. This lets plugins and apps intercept, veto, and react to deletions for cleanup, auditing, and sync. - **New Features** - Delete hooks in BetterAuthOptions for user, session, account, and verification. - Before/after hooks; before can return false to prevent deletion. - deleteWithHooks and deleteManyWithHooks helpers in with-hooks.ts. - Internal adapter updated to use hook-based deletes across the codebase. - Full TypeScript typing for the new 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-13 09:10: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#13852