mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 06:09:08 +03:00
* feat: add mfa enforcement toggle Allows toggling MFA enforcement on an organization level. Depends on API change #22088 * fix: toggle and disable action for non-owner * chore: disable for free plans * chore: disable toggle for org MFA if current user doesn't have MFA enabled * set initial state * move org mfa to security page * use zod resolver * fix initial values * useQueryClient in the organization-mfa-mutation * chore: warn about losing access to mfa orgs * Some refactors, fixes and improvements * chore: feature flag mfa enforce page * Tiny fix * Leave comment --------- Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { organizationKeys } from './keys'
|
|
|
|
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 }: UseQueryOptions<boolean, OrganizationMfaError, TData> = {}
|
|
) =>
|
|
useQuery<boolean, OrganizationMfaError, TData>(
|
|
organizationKeys.mfa(slug),
|
|
({ signal }) => getOrganizationMfaEnforcement({ slug }, signal),
|
|
{
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|