🗑️ fix: Remove All User Metadata on Deletion (#10534)

* remove all user metadata on deletion

* chore: import order

* fix: Update JSDoc types for deleteMessages function parameters and return value

* fix: Enhance user deletion process by removing associated data and updating group memberships

* fix: Add missing config middleware to user deletion route

* fix: Refactor agent and prompt deletion processes to bulk delete and remove associated ACL entries

* fix: Add deletion of OAuth tokens and ACL entries in user deletion process

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
WhammyLeaf 2025-11-21 18:03:26 +01:00 committed by GitHub
parent 7aa8d49f3a
commit 846e34b1d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 144 additions and 42 deletions

View file

@ -5,6 +5,7 @@ import {
deleteMessages,
deleteAllUserSessions,
} from '@librechat/backend/models';
import { User, Balance, Transaction, AclEntry, Token, Group } from '@librechat/backend/db/models';
type TUser = { email: string; password: string };
@ -40,13 +41,13 @@ export default async function cleanupUser(user: TUser) {
// Delete all user sessions
await deleteAllUserSessions(userId.toString());
// Get models from the registered models
const { User, Balance, Transaction } = getModels();
// Delete user, balance, and transactions using the registered models
await User.deleteMany({ _id: userId });
// Delete user, balance, transactions, tokens, ACL entries, and remove from groups
await Balance.deleteMany({ user: userId });
await Transaction.deleteMany({ user: userId });
await Token.deleteMany({ userId: userId });
await AclEntry.deleteMany({ principalId: userId });
await Group.updateMany({ memberIds: userId }, { $pull: { memberIds: userId } });
await User.deleteMany({ _id: userId });
console.log('🤖: ✅ Deleted user from Database');