import { useDataSource } from "@erp/core/hooks";
import { useQuery } from "@tanstack/react-query";
import { useAuth } from "../hooks";
import { User } from "./types";

export const useCurrentUser = () => {
  const { token } = useAuth();
  const client = useDataSource();

  return useQuery({
    queryKey: ["me"],
    queryFn: () => client.getOne<User>("/auth", "me"),
    enabled: !!token,
    staleTime: 1000 * 60 * 5,
  });
};
