[PR #3885] [MERGED] fix: prematurely deleting active sessions in secondary storage #5062

Closed
opened 2026-03-13 12:09:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3885
Author: @DevDuki
Created: 8/8/2025
Status: Merged
Merged: 12/6/2025
Merged by: @Bekacru

Base: canaryHead: fix/prematurely-deleting-active-sessions-in-deleteUser


📝 Commits (6)

  • 210a435 fix: prematurely deleting active sessions in secondary storage when deleting user with internalAdapter.deleteUser
  • d367af9 fix: remove dangling active-sessions-[userId] key in secondary storage after deleting all sessions from that list
  • dfc5242 fix: format code
  • a00ea3c fix: remove deleting the active-sessions list in secondary when providing a list of token sessions in deleteSessions
  • 0b43d80 fix: add a test for deleting a user with multiple active sessions and make sure all of them are deleted properly
  • e5cefe8 fix: format code

📊 Changes

2 files changed (+52 additions, -5 deletions)

View changed files

📝 packages/better-auth/src/api/routes/update-user.test.ts (+49 -1)
📝 packages/better-auth/src/db/internal-adapter.ts (+3 -4)

📄 Description

fixes #3882

For context, see: https://discord.com/channels/1288403910284935179/1403382349718229022

imo the deleteUser function needs some refactoring. It does too many things, like deleting accounts and sessions, which deleteAccounts and deleteSessions should be responsible for. I didn't refactor it myself, because I am not sure if it would cause any regessions on the other usages. Maybe someone with more knowledge can chime in?


Summary by cubic

Fixed deletion to remove sessions first and clear active-sessions only when deleting by userId.

Written for commit e5cefe8e22. Summary will update automatically 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/3885 **Author:** [@DevDuki](https://github.com/DevDuki) **Created:** 8/8/2025 **Status:** ✅ Merged **Merged:** 12/6/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/prematurely-deleting-active-sessions-in-deleteUser` --- ### 📝 Commits (6) - [`210a435`](https://github.com/better-auth/better-auth/commit/210a43593b8a527da37615a177ca6d974535033a) fix: prematurely deleting active sessions in secondary storage when deleting user with internalAdapter.deleteUser - [`d367af9`](https://github.com/better-auth/better-auth/commit/d367af99f243779ec1e9c9764122171c5202676b) fix: remove dangling active-sessions-[userId] key in secondary storage after deleting all sessions from that list - [`dfc5242`](https://github.com/better-auth/better-auth/commit/dfc524269a87c985e35cf36d99713050a2662536) fix: format code - [`a00ea3c`](https://github.com/better-auth/better-auth/commit/a00ea3cafb4bab32d5f7269f32744db0aa98becf) fix: remove deleting the active-sessions list in secondary when providing a list of token sessions in deleteSessions - [`0b43d80`](https://github.com/better-auth/better-auth/commit/0b43d808b7ee963220d21fff0bc4e48b95df76c6) fix: add a test for deleting a user with multiple active sessions and make sure all of them are deleted properly - [`e5cefe8`](https://github.com/better-auth/better-auth/commit/e5cefe8e220df2c1222c90beddc8bd10ac90d6fa) fix: format code ### 📊 Changes **2 files changed** (+52 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+49 -1) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+3 -4) </details> ### 📄 Description fixes #3882 For context, see: https://discord.com/channels/1288403910284935179/1403382349718229022 imo the `deleteUser` function needs some refactoring. It does too many things, like deleting accounts and sessions, which `deleteAccounts` and `deleteSessions` should be responsible for. I didn't refactor it myself, because I am not sure if it would cause any regessions on the other usages. Maybe someone with more knowledge can chime in? <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed deletion to remove sessions first and clear active-sessions only when deleting by userId. <sup>Written for commit e5cefe8e220df2c1222c90beddc8bd10ac90d6fa. Summary will update automatically 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-03-13 12:09:33 -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#5062