mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { organizationKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type OrganizationMfaVariables = {
|
|
slug?: string
|
|
}
|
|
|
|
export async function getOrganizationMfaEnforcement(
|
|
{ slug }: OrganizationMfaVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!slug) throw new Error('slug is required')
|
|
|
|
const orgMfa = await get('/platform/organizations/{slug}/members/mfa/enforcement', {
|
|
params: { path: { slug } },
|
|
signal,
|
|
})
|
|
|
|
const { data: orgMfaRequired, error: orgMfaError } = orgMfa
|
|
|
|
if (orgMfaError) handleError(orgMfaError)
|
|
|
|
return orgMfaRequired?.enforced
|
|
}
|
|
|
|
export type OrganizationMfaError = ResponseError
|
|
|
|
export const useOrganizationMfaQuery = <TData = boolean>(
|
|
{ slug }: OrganizationMfaVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<boolean, OrganizationMfaError, TData> = {}
|
|
) =>
|
|
useQuery<boolean, OrganizationMfaError, TData>({
|
|
queryKey: organizationKeys.mfa(slug),
|
|
queryFn: ({ signal }) => getOrganizationMfaEnforcement({ slug }, signal),
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
})
|