mirror of
https://github.com/supabase/supabase.git
synced 2026-06-22 01:02:52 +08:00
## Context Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix all related issues
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { orgSSOKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type OrgSSOConfigVariables = {
|
|
orgSlug?: string
|
|
}
|
|
|
|
export async function getOrgSSOConfig({ orgSlug }: OrgSSOConfigVariables, signal?: AbortSignal) {
|
|
if (!orgSlug) throw new Error('Organization slug is required')
|
|
|
|
const { data, error } = await get('/platform/organizations/{slug}/sso', {
|
|
params: { path: { slug: orgSlug } },
|
|
signal,
|
|
})
|
|
|
|
if (error) {
|
|
const ssoNotSetUp =
|
|
(error as any)?.code === 404 &&
|
|
(error as any)?.message?.includes('Failed to find an existing SSO Provider')
|
|
|
|
if (ssoNotSetUp) {
|
|
return null
|
|
} else {
|
|
handleError(error)
|
|
}
|
|
}
|
|
return data
|
|
}
|
|
|
|
export type OrgSSOConfigData = Awaited<ReturnType<typeof getOrgSSOConfig>>
|
|
export type OrgSSOConfigError = ResponseError
|
|
|
|
export const useOrgSSOConfigQuery = <TData = OrgSSOConfigData>(
|
|
{ orgSlug }: OrgSSOConfigVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OrgSSOConfigData, OrgSSOConfigError, TData> = {}
|
|
) => {
|
|
return useQuery<OrgSSOConfigData, OrgSSOConfigError, TData>({
|
|
queryKey: orgSSOKeys.orgSSOConfig(orgSlug),
|
|
queryFn: ({ signal }) => getOrgSSOConfig({ orgSlug }, signal),
|
|
enabled: enabled && IS_PLATFORM && typeof orgSlug !== 'undefined',
|
|
...options,
|
|
})
|
|
}
|