import { useQuery } from '@tanstack/react-query' import { components } from 'api-types' import { get, handleError } from 'data/fetchers' import type { ResponseError, UseCustomQueryOptions } 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 > export const useThirdPartyAuthIntegrationsQuery = ( { projectRef }: GetThirdPartyAuthIntegrationsVariables, { enabled = true, ...options }: UseCustomQueryOptions = {} ) => useQuery({ queryKey: keys.integrations(projectRef), queryFn: ({ signal }) => getThirdPartyAuthIntegrations({ projectRef }, signal), enabled: enabled && typeof projectRef !== 'undefined', ...options, })