33 lines
716 B
TypeScript
33 lines
716 B
TypeScript
// imports
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
|
import { useAuth } from "~/composables/api/auth/useAuth";
|
|
|
|
// types
|
|
|
|
export type GetAccountResponse = Product;
|
|
|
|
const useGetAccount = () => {
|
|
|
|
// state
|
|
|
|
const { $axios: axios } = useNuxtApp();
|
|
const { token } = useAuth();
|
|
|
|
// methods
|
|
|
|
const handleGetAccount = async () => {
|
|
const { data } = await axios.get<GetAccountResponse>(`${API_ENDPOINTS.account.profile}`);
|
|
return data;
|
|
};
|
|
|
|
return useQuery({
|
|
enabled: !!token.value,
|
|
queryKey: [QUERY_KEYS.account],
|
|
queryFn: () => handleGetAccount()
|
|
});
|
|
};
|
|
|
|
export default useGetAccount;
|