mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 21:29:08 +03:00
* Add custom error handler for fetch error 'Failed to fetch' * Refactor EdgeFunctionTesterSheet to use react query instead of manually calling fetch * Use new fetchHandler for where we're calling fetch * Revert
29 lines
930 B
TypeScript
29 lines
930 B
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { fetchHandler } from 'data/fetchers'
|
|
import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
|
|
import type { ResponseError } from 'types'
|
|
import { miscKeys } from './keys'
|
|
|
|
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<ReturnType<typeof getUserIPAddress>>
|
|
export type UserIPAddressError = ResponseError
|
|
|
|
export const useUserIPAddressQuery = <TData = UserIPAddressData>({
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<UserIPAddressData, UserIPAddressError, TData> = {}) =>
|
|
useQuery<UserIPAddressData, UserIPAddressError, TData>(
|
|
miscKeys.ipAddress(),
|
|
() => getUserIPAddress(),
|
|
{ enabled: enabled && !IS_PLATFORM, ...options }
|
|
)
|