mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 05:39:11 +03:00
* Update several files to use data fetcher methods
* Remove unused files from lib/common/fetch
* Revert "Remove unused files from lib/common/fetch"
This reverts commit b314b05f06.
* Fix GraphQL
* Fix types
* Add IS_PLATFORM check in useOrgUsageQuery
* Fix type issues
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { components } from 'api-types'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { oauthAppKeys } from './keys'
|
|
|
|
export type OAuthAppsVariables = {
|
|
slug?: string
|
|
}
|
|
|
|
export type OAuthApp = components['schemas']['OAuthAppResponse']
|
|
|
|
export async function getOAuthApps({ slug }: OAuthAppsVariables, signal?: AbortSignal) {
|
|
if (!slug) throw new Error('Organization slug is required')
|
|
|
|
const { data, error } = await get('/platform/organizations/{slug}/oauth/apps', {
|
|
params: { path: { slug }, query: { type: 'published' } },
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type OAuthAppsData = Awaited<ReturnType<typeof getOAuthApps>>
|
|
export type OAuthAppsError = ResponseError
|
|
|
|
export const useOAuthAppsQuery = <TData = OAuthAppsData>(
|
|
{ slug }: OAuthAppsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<OAuthAppsData, OAuthAppsError, TData> = {}
|
|
) =>
|
|
useQuery<OAuthAppsData, OAuthAppsError, TData>(
|
|
oauthAppKeys.oauthApps(slug),
|
|
({ signal }) => getOAuthApps({ slug }, signal),
|
|
{
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|