added cart fetching only if login
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
||||
import { useAuth } from "../auth/useAuth";
|
||||
|
||||
// types
|
||||
|
||||
@@ -12,17 +13,18 @@ const useGetCartOrders = () => {
|
||||
|
||||
const { $axios: axios } = useNuxtApp();
|
||||
|
||||
const { token } = useAuth();
|
||||
|
||||
// methods
|
||||
|
||||
const handleGetCartOrders = async () => {
|
||||
const { data } = await axios.get<GetCartOrdersResponse>(
|
||||
API_ENDPOINTS.orders.cart.get_all
|
||||
);
|
||||
const { data } = await axios.get<GetCartOrdersResponse>(API_ENDPOINTS.orders.cart.get_all);
|
||||
return data;
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: [QUERY_KEYS.cart],
|
||||
enabled: !!token.value,
|
||||
queryFn: () => handleGetCartOrders(),
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user