mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 09:59:03 +08:00
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { components } from 'api-types'
|
|
|
|
import { clientSecretKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type Secret =
|
|
components['schemas']['ListOAuthAppClientSecretsResponse']['client_secrets'][0] & {
|
|
client_secret?: components['schemas']['CreateOAuthAppClientSecretResponse']['client_secret']
|
|
}
|
|
|
|
export type CreatedSecret = components['schemas']['CreateOAuthAppClientSecretResponse']
|
|
|
|
export interface SecretRowProps {
|
|
secret: Secret
|
|
appId?: string
|
|
isNew?: boolean
|
|
}
|
|
|
|
type ClientSecretsVariables = {
|
|
slug?: string
|
|
appId?: string
|
|
}
|
|
|
|
export async function getClientSecrets(
|
|
{ slug, appId }: ClientSecretsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!slug) throw new Error('slug is required')
|
|
if (!appId) throw new Error('appId is required')
|
|
|
|
const { data, error } = await get(
|
|
'/platform/organizations/{slug}/oauth/apps/{app_id}/client-secrets',
|
|
{
|
|
params: {
|
|
path: { slug, app_id: appId },
|
|
},
|
|
signal,
|
|
}
|
|
)
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ClientSecretsData = Awaited<ReturnType<typeof getClientSecrets>>
|
|
export type ClientSecretsError = ResponseError
|
|
|
|
export const useClientSecretsQuery = <TData = ClientSecretsData>(
|
|
{ slug, appId }: ClientSecretsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<ClientSecretsData, ClientSecretsError, TData> = {}
|
|
) =>
|
|
useQuery<ClientSecretsData, ClientSecretsError, TData>({
|
|
queryKey: clientSecretKeys.list(slug, appId),
|
|
queryFn: ({ signal }) => getClientSecrets({ slug, appId }, signal),
|
|
enabled: enabled && typeof slug !== 'undefined' && typeof appId !== 'undefined',
|
|
...options,
|
|
})
|