import { useQuery } from '@tanstack/react-query' import { miscKeys } from './keys' import { fetchHandler } from '@/data/fetchers' import { BASE_PATH, IS_PLATFORM } from '@/lib/constants' import type { ResponseError, UseCustomQueryOptions } from '@/types' export async function getUserIPAddress() { try { const data = await fetchHandler(`${BASE_PATH}/api/get-ip-address`).then((res) => res.json()) return data.ipAddress } catch (error) { throw error } } export type UserIPAddressData = Awaited> export type UserIPAddressError = ResponseError export const useUserIPAddressQuery = ({ enabled = true, ...options }: UseCustomQueryOptions = {}) => useQuery({ queryKey: miscKeys.ipAddress(), queryFn: () => getUserIPAddress(), enabled: enabled && !IS_PLATFORM, ...options, })