Files
supabase/apps/studio/data/third-party-auth/integrations-query.ts
Alaister YoungandJoshen Lim 8855d05803 chore(studio): swap react-query to object syntax (#39842)
* chore(studio): swap react-query to object syntax

* Fix small issues found

* Fix realtime settings

* Nit

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-10-27 09:38:27 +01:00

45 lines
1.4 KiB
TypeScript

import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { components } from 'api-types'
import { get, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { keys } from './keys'
export type GetThirdPartyAuthIntegrationsVariables = {
projectRef?: string
}
export type ThirdPartyAuthIntegration = components['schemas']['ThirdPartyAuth']
export async function getThirdPartyAuthIntegrations(
{ projectRef }: GetThirdPartyAuthIntegrationsVariables,
signal?: AbortSignal
) {
if (!projectRef) throw new Error('projectRef is required')
const { data, error } = await get('/v1/projects/{ref}/config/auth/third-party-auth', {
params: { path: { ref: projectRef } },
signal,
})
if (error) handleError(error)
return data
}
export type ThirdPartyAuthIntegrationsData = Awaited<
ReturnType<typeof getThirdPartyAuthIntegrations>
>
export const useThirdPartyAuthIntegrationsQuery = <TData = ThirdPartyAuthIntegrationsData>(
{ projectRef }: GetThirdPartyAuthIntegrationsVariables,
{
enabled = true,
...options
}: UseQueryOptions<ThirdPartyAuthIntegrationsData, ResponseError, TData> = {}
) =>
useQuery<ThirdPartyAuthIntegrationsData, ResponseError, TData>({
queryKey: keys.integrations(projectRef),
queryFn: ({ signal }) => getThirdPartyAuthIntegrations({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
})