-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhook.ts
More file actions
24 lines (21 loc) · 946 Bytes
/
hook.ts
File metadata and controls
24 lines (21 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { useQueryClient } from '@tanstack/react-query';
import { authApi } from '@open-webui-react-native/shared/data-access/api';
import { authState$ } from '@open-webui-react-native/shared/data-access/auth';
import { cookieService } from '@open-webui-react-native/shared/data-access/cookie';
import { queryPersister } from '@open-webui-react-native/shared/data-access/persist-query-storage';
export const useLogout = (): { logout: () => Promise<void>; isLoading: boolean } => {
const queryClient = useQueryClient();
const { mutateAsync: signOut, isPending } = authApi.useSignOut();
const logout = async (): Promise<void> => {
try {
await signOut();
} catch {
// Session may already be gone; still wipe client state and redirect.
}
authState$.logout();
queryClient.removeQueries();
cookieService.clearAll();
await queryPersister.removeClient();
};
return { logout, isLoading: isPending };
};