mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { components } from 'api-types'
|
|
|
|
import { oauthServerAppKeys } from './keys'
|
|
import { useAuthConfigQuery } from '@/data/auth/auth-config-query'
|
|
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
|
|
import { handleError } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import { createProjectSupabaseClient } from '@/lib/project-supabase-client'
|
|
import type { UseCustomQueryOptions } from '@/types'
|
|
|
|
export type OAuthServerAppsVariables = {
|
|
projectRef: string | undefined
|
|
page?: number
|
|
}
|
|
|
|
const APPS_PER_PAGE = 100
|
|
|
|
export type OAuthApp = components['schemas']['OAuthAppResponse_Output']
|
|
|
|
export async function getOAuthServerApps({
|
|
projectRef,
|
|
clientEndpoint,
|
|
page = 1,
|
|
}: OAuthServerAppsVariables & { clientEndpoint: string | undefined }) {
|
|
if (!projectRef) throw new Error('Project reference is required')
|
|
if (!clientEndpoint) throw new Error('Client endpoint is required')
|
|
|
|
const supabaseClient = await createProjectSupabaseClient(projectRef, clientEndpoint)
|
|
|
|
const { data, error } = await supabaseClient.auth.admin.oauth.listClients({
|
|
page,
|
|
perPage: APPS_PER_PAGE,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type OAuthServerAppsData = Awaited<ReturnType<typeof getOAuthServerApps>>
|
|
export type OAuthServerAppsError = StudioError
|
|
|
|
export const useOAuthServerAppsQuery = <TData = OAuthServerAppsData>(
|
|
{ projectRef }: OAuthServerAppsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OAuthServerAppsData, OAuthServerAppsError, TData> = {}
|
|
) => {
|
|
const { hostEndpoint: clientEndpoint } = useProjectApiUrl({ projectRef })
|
|
const { data: authConfig, isSuccess: isSuccessConfig } = useAuthConfigQuery({ projectRef })
|
|
const isOAuthServerEnabled = !!authConfig?.OAUTH_SERVER_ENABLED
|
|
|
|
return useQuery<OAuthServerAppsData, OAuthServerAppsError, TData>({
|
|
queryKey: oauthServerAppKeys.list(projectRef, clientEndpoint),
|
|
queryFn: () => getOAuthServerApps({ projectRef, clientEndpoint }),
|
|
enabled:
|
|
enabled &&
|
|
typeof projectRef !== 'undefined' &&
|
|
!!clientEndpoint &&
|
|
isSuccessConfig &&
|
|
isOAuthServerEnabled,
|
|
...options,
|
|
})
|
|
}
|