🚫👤feat: delete user from UI (#1526)

* initial commit

* fix: UserController bugs; fix: lint errors

* fix: delete files

* language support

* style(DeleteAccount): update to the latest style

* style: fix after merge main

* chore: Add canDeleteAccount middleware for user deletion endpoint

* chore: renamed to ALLOW_ACCOUNT_DELETION

* fix(canDeleteAccount): use uppercase admin role

* chore: imports order

* chore: Enable account deletion by default if omitted/commented out

* chore: Add logging for user account deletion

* chore: Bump data-provider package version to 0.6.6

* chore: Import Transaction model in UserController

* chore: Update CONFIG_VERSION to 1.1.4

* chore: Update user account deletion logging

* chore: Refactor user account deletion logic

---------

Co-authored-by: Berry-13 <root@Berry>
Co-authored-by: Danny Avila <messagedaniel@protonmail.com>
Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Marco Beretta 2024-06-06 01:35:12 +02:00 committed by GitHub
parent f69b317171
commit a7f5b57272
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 348 additions and 17 deletions

View file

@ -3,22 +3,22 @@ import {
LocalStorageKeys,
defaultAssistantsVersion,
} from 'librechat-data-provider';
import { useSetRecoilState } from 'recoil';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { dataService, MutationKeys, QueryKeys, defaultOrderQuery } from 'librechat-data-provider';
import type { UseMutationResult } from '@tanstack/react-query';
import type t from 'librechat-data-provider';
import {
addSharedLink,
addConversation,
deleteSharedLink,
updateConvoFields,
updateConversation,
deleteConversation,
updateConvoFields,
deleteSharedLink,
addSharedLink,
} from '~/utils';
import { dataService, MutationKeys, QueryKeys, defaultOrderQuery } from 'librechat-data-provider';
import { useSetRecoilState } from 'recoil';
import store from '~/store';
import { normalizeData } from '~/utils/collection';
import { useConversationsInfiniteQuery, useSharedLinksInfiniteQuery } from './queries';
import { normalizeData } from '~/utils/collection';
import store from '~/store';
/** Conversations */
export const useGenTitleMutation = (): UseMutationResult<
@ -609,6 +609,30 @@ export const useUploadAvatarMutation = (
});
};
export const useDeleteUserMutation = (
options?: t.MutationOptions<unknown, undefined>,
): UseMutationResult<unknown, unknown, undefined, unknown> => {
const queryClient = useQueryClient();
const setDefaultPreset = useSetRecoilState(store.defaultPreset);
return useMutation([MutationKeys.deleteUser], {
mutationFn: () => dataService.deleteUser(),
...(options || {}),
onSuccess: (...args) => {
options?.onSuccess?.(...args);
},
onMutate: (...args) => {
setDefaultPreset(null);
queryClient.removeQueries();
localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
options?.onMutate?.(...args);
},
});
};
/* Speech to text */
export const useSpeechToTextMutation = (
options?: t.SpeechToTextOptions,