mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 07:50:20 +08:00
* Add custom types for queries, mutations and infinite queries. * Migrate all queries to use the new type. * Migrate all infinite queries to useCustomInfiniteQueryOptions. * Migrate all mutations to use useCustomMutationOptions. * Add type to all imports in `types` folder.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import type { OAuthScope } from '@supabase/shared-types/out/constants'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { resourceKeys } from './keys'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
export type ApiAuthorizationVariables = {
|
|
id?: string
|
|
}
|
|
|
|
export type ApiAuthorizationResponse = {
|
|
name: string
|
|
website: string
|
|
icon: string | null
|
|
domain: string
|
|
scopes: OAuthScope[]
|
|
expires_at: string
|
|
approved_at: string | null
|
|
approved_organization_slug?: string
|
|
registration_type: string
|
|
}
|
|
|
|
export async function getApiAuthorizationDetails(
|
|
{ id }: ApiAuthorizationVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!id) throw new Error('Authorization ID is required')
|
|
|
|
const { data, error } = await get('/platform/oauth/authorizations/{id}', {
|
|
params: { path: { id } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as ApiAuthorizationResponse
|
|
}
|
|
|
|
export type ResourceData = Awaited<ReturnType<typeof getApiAuthorizationDetails>>
|
|
export type ResourceError = { errorEventId: string; message: string }
|
|
|
|
export const useApiAuthorizationQuery = <TData = ResourceData>(
|
|
{ id }: ApiAuthorizationVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<ResourceData, ResourceError, TData> = {}
|
|
) =>
|
|
useQuery<ResourceData, ResourceError, TData>({
|
|
queryKey: resourceKeys.resource(id),
|
|
queryFn: ({ signal }) => getApiAuthorizationDetails({ id }, signal),
|
|
enabled: enabled && typeof id !== 'undefined',
|
|
...options,
|
|
})
|