mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
🔒 fix: Robust Cache Reset on User Logout (#1324)
* refactor(Logout): rely on hooks for mutation behavior * fix: logging out now correctly resets cache, disallowing any cache mixing between the next logged in user on the same browser * chore: remove additional localStorage values on logout
This commit is contained in:
parent
583e978a82
commit
968b8ccdbd
10 changed files with 109 additions and 90 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import type {
|
||||
FileUploadResponse,
|
||||
|
|
@ -10,9 +10,13 @@ import type {
|
|||
UpdatePresetOptions,
|
||||
DeletePresetOptions,
|
||||
PresetDeleteResponse,
|
||||
LogoutOptions,
|
||||
TPreset,
|
||||
} from 'librechat-data-provider';
|
||||
|
||||
import { dataService, MutationKeys } from 'librechat-data-provider';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import store from '~/store';
|
||||
|
||||
export const useUploadImageMutation = (
|
||||
options?: UploadMutationOptions,
|
||||
|
|
@ -69,3 +73,29 @@ export const useDeletePresetMutation = (
|
|||
...(options || {}),
|
||||
});
|
||||
};
|
||||
|
||||
/* login/logout */
|
||||
export const useLogoutUserMutation = (
|
||||
options?: LogoutOptions,
|
||||
): UseMutationResult<unknown, unknown, undefined, unknown> => {
|
||||
const queryClient = useQueryClient();
|
||||
const setDefaultPreset = useSetRecoilState(store.defaultPreset);
|
||||
return useMutation([MutationKeys.logoutUser], {
|
||||
mutationFn: () => dataService.logout(),
|
||||
|
||||
...(options || {}),
|
||||
onSuccess: (...args) => {
|
||||
options?.onSuccess?.(...args);
|
||||
},
|
||||
onMutate: (...args) => {
|
||||
setDefaultPreset(null);
|
||||
queryClient.removeQueries();
|
||||
localStorage.removeItem('lastConversationSetup');
|
||||
localStorage.removeItem('lastSelectedModel');
|
||||
localStorage.removeItem('lastSelectedTools');
|
||||
localStorage.removeItem('filesToDelete');
|
||||
localStorage.removeItem('lastAssistant');
|
||||
options?.onMutate?.(...args);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue