import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { apiFetch, apiPost } from '../lib/api' import type { SessionResponse } from '../types' export function useSession() { return useQuery({ queryKey: ['session'], queryFn: () => apiFetch('/api/v1/session'), staleTime: 60_000, }) } export function useLogout() { const queryClient = useQueryClient() return useMutation({ mutationFn: () => apiPost('/api/v1/auth/logout'), // Full reload rather than just invalidating the session query — clears // any in-memory query cache holding data from the now-logged-out user, // and re-runs App.tsx's session check from a clean slate. onSuccess: () => { queryClient.clear() window.location.assign('/') }, }) }