Files
supabase/apps/studio/data/oauth/authorized-apps-query.ts
Kamil Ogórek 315a189577 feat: Add created_by and app_id to approved oauth apps table (#34045)
* feat: Add created_by to approved apps table

* feat: Add app_id to approved apps table
2025-03-14 10:43:28 +01:00

50 lines
1.4 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { oauthAppKeys } from './keys'
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, 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: '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
}: UseQueryOptions<AuthorizedAppsData, AuthorizedAppsError, TData> = {}
) =>
useQuery<AuthorizedAppsData, AuthorizedAppsError, TData>(
oauthAppKeys.authorizedApps(slug),
({ signal }) => getAuthorizedApps({ slug }, signal),
{
enabled: enabled && typeof slug !== 'undefined',
...options,
}
)