import { useQuery } from "@tanstack/react-query";
import { API_Instance } from "../api/axios.instance";

// useAuthQuery.ts
export const useAuthQuery = () => {
    return useQuery({
        queryKey: ["authUser"],
        queryFn: async () => {
            const res = await API_Instance.get("/auth/me");
            // support both shapes: res.data.user or res.user
            return res?.data?.user ?? res?.data ?? null;
        },
        retry: false,
        // allow the query to be run even if token is not in localStorage at mount,
        // we'll handle no-token server response gracefully
        enabled: true,
    });
};

