[GH-ISSUE #7612] The hook is never called on sign-out. Only deleteSessions uses deleteManyWithHooks, while deleteSession bypasses hooks entirely. #28176

Closed
opened 2026-04-17 19:35:30 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @yukiyamamuro on GitHub (Jan 26, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7612

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure databaseHooks.session.delete.after in auth config
  2. Sign in to create a session
  3. Call betterAuthClient.signOut()
  4. Check if the hook was triggered (it won't be)

Current vs. Expected behavior

Current: databaseHooks.session.delete.after is not called when signing out via /sign-out endpoint. deleteSession() uses direct adapter.delete() instead of deleteWithHooks().

Expected: The hook should be triggered on sign-out, consistent with deleteSessions() which uses deleteManyWithHooks().

What version of Better Auth are you using?

1.4.4

System info

{
    "os": "Darwin 25.2.0",
    "node": "v22.18.0",
    "betterAuth": "1.4.4",
    "framework": "hono"
  }

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)


Additional context

Related to #4766 which added delete hooks, but deleteSession was not updated to use them.
Code reference: src/db/internal-adapter.ts - deleteSession vs deleteSessions

Originally created by @yukiyamamuro on GitHub (Jan 26, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7612 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure databaseHooks.session.delete.after in auth config 2. Sign in to create a session 3. Call betterAuthClient.signOut() 4. Check if the hook was triggered (it won't be) ### Current vs. Expected behavior **Current**: databaseHooks.session.delete.after is not called when signing out via /sign-out endpoint. deleteSession() uses direct adapter.delete() instead of deleteWithHooks(). **Expected**: The hook should be triggered on sign-out, consistent with deleteSessions() which uses deleteManyWithHooks(). ### What version of Better Auth are you using? 1.4.4 ### System info ```bash { "os": "Darwin 25.2.0", "node": "v22.18.0", "betterAuth": "1.4.4", "framework": "hono" } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context Related to #4766 which added delete hooks, but deleteSession was not updated to use them. Code reference: src/db/internal-adapter.ts - deleteSession vs deleteSessions
GiteaMirror added the lockedbug labels 2026-04-17 19:35:30 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 26, 2026):

It looks like you have encountered an issue where the deleteSession() function bypasses hooks during sign-out, while deleteSessions() properly triggers them. This behavior is indeed confirmed in the context of Better Auth, where deleteSession() directly invokes the adapter's delete method instead of the hook-enabled version.

To resolve this, you may want to ensure you're using the latest version of Better Auth available and check if the current behavior was modified in subsequent updates. Based on the records, there was a fix implemented that replaced direct session deletes with hook-based deletes for the sign-out process, so make sure this is reflected in your setup.

For future assistance or if there's any lingering confusion, please tag @better-auth-agent for a more detailed look into your issue.

Is there anything else specific you're looking to achieve with Better Auth?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3797667207 --> @better-auth-agent[bot] commented on GitHub (Jan 26, 2026): It looks like you have encountered an issue where the `deleteSession()` function bypasses hooks during sign-out, while `deleteSessions()` properly triggers them. This behavior is indeed confirmed in the context of Better Auth, where `deleteSession()` directly invokes the adapter's delete method instead of the hook-enabled version. To resolve this, you may want to ensure you're using the latest version of Better Auth available and check if the current behavior was modified in subsequent updates. Based on the records, there was a fix implemented that replaced direct session deletes with hook-based deletes for the sign-out process, so make sure this is reflected in your setup. For future assistance or if there's any lingering confusion, please tag @better-auth-agent for a more detailed look into your issue. Is there anything else specific you're looking to achieve with Better Auth? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Jan 26, 2026):

Hi @yukiyamamuro! I'm Dosu and I’m helping the better-auth team.

You're correct—when signing out via betterAuthClient.signOut() in v1.4.4, the databaseHooks.session.delete.after hook is not always triggered. This happens because deleteSession only calls deleteWithHooks if the session is stored in the database and not preserved; otherwise, it bypasses hook invocation and deletes directly from secondary storage. In contrast, deleteSessions consistently uses deleteManyWithHooks, ensuring hooks run for bulk deletions, which leads to the inconsistency you observed source.

This behavior is a side effect of how storage configuration (database vs. secondary storage, preserveSessionInDatabase) impacts the deletion flow. The intention behind PR #4792 (which fixed #4766) was for all delete paths to run through hooks, but in practice, deleteSession does not always trigger them depending on your setup source.

If you need hooks to run reliably on sign-out, a practical workaround is to use a custom endpoint or explicitly call the bulk deletion logic (deleteSessions) instead of deleteSession, or adjust your configuration so sessions are always stored in the database. There are related issues showing similar inconsistencies across plugins and endpoints, and workarounds often involve custom hooks or endpoint logic source.

Let me know if you want a code example or more details on implementing a workaround.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3797670584 --> @dosubot[bot] commented on GitHub (Jan 26, 2026): <!-- Greeting --> Hi @yukiyamamuro! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're correct—when signing out via betterAuthClient.signOut() in v1.4.4, the databaseHooks.session.delete.after hook is not always triggered. This happens because deleteSession only calls deleteWithHooks if the session is stored in the database and not preserved; otherwise, it bypasses hook invocation and deletes directly from secondary storage. In contrast, deleteSessions consistently uses deleteManyWithHooks, ensuring hooks run for bulk deletions, which leads to the inconsistency you observed [source](https://github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/db/internal-adapter.ts#L591-L717). This behavior is a side effect of how storage configuration (database vs. secondary storage, preserveSessionInDatabase) impacts the deletion flow. The intention behind PR #4792 (which fixed #4766) was for all delete paths to run through hooks, but in practice, deleteSession does not always trigger them depending on your setup [source](https://github.com/better-auth/better-auth/pull/4792). If you need hooks to run reliably on sign-out, a practical workaround is to use a custom endpoint or explicitly call the bulk deletion logic (deleteSessions) instead of deleteSession, or adjust your configuration so sessions are always stored in the database. There are related issues showing similar inconsistencies across plugins and endpoints, and workarounds often involve custom hooks or endpoint logic [source](https://github.com/better-auth/better-auth/issues/5868). Let me know if you want a code example or more details on implementing a workaround. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/61078619-7bfb-4961-a0d4-45da11311b2e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%27re%20correct%E2%80%94when%20signing%20out%20via%20betterAuthClient.signOut%28%29%20in%20v1.4.4%2C%20the%20databaseHooks.session.delete.after%20hook%20is%20not%20always%20triggered.%20This%20happens%20because%20deleteSession%20only%20calls%20deleteWithHooks%20if%20the%20session%20is%20stored%20in%20the%20database%20and%20not%20preserved%3B%20otherwise%2C%20it%20bypasses%20hook%20invocation%20and%20deletes%20directly%20from%20secondary%20storage.%20In%20contrast%2C%20deleteSessions%20consistently%20uses%20deleteManyWithHooks%2C%20ensuring%20hooks%20run%20for%20bulk%20deletions%2C%20which%20leads%20to%20the%20inconsistency%20you%20observed%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/d1602ef0ae9822e462a5a42497072a0a1756e804/packages/better-auth/src/db/internal-adapter.ts%23L591-L717%29.%0A%0AThis%20behavior%20is%20a%20side%20effect%20of%20how%20storage%20configuration%20%28database%20vs.%20secondary%20storage%2C%20preserveSessionInDatabase%29%20impacts%20the%20deletion%20flow.%20The%20intention%20behind%20PR%20%234792%20%28which%20fixed%20%234766%29%20was%20for%20all%20delete%20paths%20to%20run%20through%20hooks%2C%20but%20in%20practice%2C%20deleteSession%20does%20not%20always%20trigger%20them%20depending%20on%20your%20setup%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/pull/4792%29.%0A%0AIf%20you%20need%20hooks%20to%20run%20reliably%20on%20sign-out%2C%20a%20practical%20workaround%20is%20to%20use%20a%20custom%20endpoint%20or%20explicitly%20call%20the%20bulk%20deletion%20logic%20%28deleteSessions%29%20instead%20of%20deleteSession%2C%20or%20adjust%20your%20configuration%20so%20sessions%20are%20always%20stored%20in%20the%20database.%20There%20are%20related%20issues%20showing%20similar%20inconsistencies%20across%20plugins%20and%20endpoints%2C%20and%20workarounds%20often%20involve%20custom%20hooks%20or%20endpoint%20logic%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/5868%29.%0A%0ALet%20me%20know%20if%20you%20want%20a%20code%20example%20or%20more%20details%20on%20implementing%20a%20workaround.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7612)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28176