Files
supabase/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts
Gildas Garcia 4442d91d77 feat(studio): Wire org and users authorized apps list to backend (#53674)
## Description

Part of the work for OAuth apps with the scoped permissions. This PR
wires the org and users authorized apps lists to backend.
2026-11-19 21:40:12 +01:00

46 lines
1.5 KiB
TypeScript

import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'
import { get, handleError } from '../fetchers'
import { oauthAppsKeys } from './keys'
import type { StudioError } from '@/lib/errors/studio-errors'
import type { UseCustomInfiniteQueryOptions } from '@/types'
export type OAuthGrantsVariables = {
cursor?: string
}
export async function getOAuthGrants({ cursor }: OAuthGrantsVariables = {}) {
const { data, error } = await get('/platform/profile/oauth/grants', {
params: { query: { page: { after: cursor } } },
})
if (error) handleError(error)
return data
}
export type OAuthGrantsData = Awaited<ReturnType<typeof getOAuthGrants>>
export type OAuthGrant = OAuthGrantsData['data'][number]
export type OAuthGrantsError = StudioError
export const useOAuthGrantsQuery = <TData = OAuthGrantsData>(
{ cursor }: OAuthGrantsVariables = {},
options: UseCustomInfiniteQueryOptions<
OAuthGrantsData,
OAuthGrantsError,
InfiniteData<TData>,
readonly unknown[],
string | undefined
> = {}
) =>
useInfiniteQuery({
queryKey: oauthAppsKeys.grants(cursor),
queryFn: ({ pageParam }) => getOAuthGrants({ cursor: pageParam }),
initialPageParam: cursor,
getNextPageParam: (lastPage) =>
lastPage.links.next
? // The URL second paramater does not matter as we only want to extract the search params
new URL(lastPage.links.next, 'http://localhost').searchParams.get('page[after]')
: null,
...options,
})