Files
hossein-por-shop/frontend/composables/api/account/useGetAccount.ts
T
marzban-dev 46aa23b7e9 Updated
2025-01-26 20:14:05 +03:30

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 = Account;
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;