Portal/rsconcept/frontend/src/backend/auth/useAuth.tsx

27 lines
660 B
TypeScript
Raw Normal View History

2025-01-21 20:33:05 +03:00
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
2025-01-29 23:18:08 +03:00
import { queryClient } from '../queryClient';
2025-01-21 20:33:05 +03:00
import { authApi } from './api';
export function useAuth() {
const {
data: user,
isLoading,
error
} = useQuery({
...authApi.getAuthQueryOptions()
});
return { user, isLoading, isAnonymous: user?.id === null || user === undefined, error };
2025-01-21 20:33:05 +03:00
}
export function useAuthSuspense() {
const { data: user } = useSuspenseQuery({
...authApi.getAuthQueryOptions()
});
return { user, isAnonymous: user.id === null };
2025-01-21 20:33:05 +03:00
}
2025-01-29 23:18:08 +03:00
export function prefetchAuth() {
return queryClient.prefetchQuery(authApi.getAuthQueryOptions());
}