24 lines
806 B
TypeScript
24 lines
806 B
TypeScript
|
|
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
||
|
|
|
||
|
|
import { fetchInstance, instanceQueryKey } from '@/api/instance';
|
||
|
|
import { fetchCurrentUser, currentUserQueryKey } from '@/api/users';
|
||
|
|
import type { InstanceInfo, User } from '@/api/types';
|
||
|
|
|
||
|
|
/** Текущий пользователь: единственный источник правды о сессии (cookie). */
|
||
|
|
export function useCurrentUser(): UseQueryResult<User> {
|
||
|
|
return useQuery({
|
||
|
|
queryKey: currentUserQueryKey,
|
||
|
|
queryFn: ({ signal }) => fetchCurrentUser(signal),
|
||
|
|
retry: false,
|
||
|
|
staleTime: 30_000,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useInstance(): UseQueryResult<InstanceInfo> {
|
||
|
|
return useQuery({
|
||
|
|
queryKey: instanceQueryKey,
|
||
|
|
queryFn: ({ signal }) => fetchInstance(signal),
|
||
|
|
staleTime: 60_000,
|
||
|
|
});
|
||
|
|
}
|