mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { oauthAppKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type AuthorizedAppsVariables = {
|
|
slug?: string
|
|
}
|
|
|
|
export type AuthorizedApp = {
|
|
id: string
|
|
app_id: string
|
|
icon: string | null
|
|
name: string
|
|
website: string
|
|
created_by: string
|
|
authorized_at: string
|
|
}
|
|
|
|
export async function getAuthorizedApps({ slug }: AuthorizedAppsVariables) {
|
|
if (!slug) throw new Error('Organization slug is required')
|
|
|
|
const { data, error } = await get('/platform/organizations/{slug}/oauth/apps', {
|
|
params: { path: { slug }, query: { type: 'authorized' } },
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as AuthorizedApp[]
|
|
}
|
|
|
|
export type AuthorizedAppsData = Awaited<ReturnType<typeof getAuthorizedApps>>
|
|
export type AuthorizedAppsError = ResponseError
|
|
|
|
export const useAuthorizedAppsQuery = <TData = AuthorizedAppsData>(
|
|
{ slug }: AuthorizedAppsVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<AuthorizedAppsData, AuthorizedAppsError, TData> = {}
|
|
) =>
|
|
useQuery<AuthorizedAppsData, AuthorizedAppsError, TData>({
|
|
queryKey: oauthAppKeys.authorizedApps(slug),
|
|
queryFn: () => getAuthorizedApps({ slug }),
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
})
|