import type { AuthMFAListFactorsResponse, Factor } from '@supabase/supabase-js' import { useQuery } from '@tanstack/react-query' import { useUser } from 'common' import { profileKeys } from './keys' import { auth } from '@/lib/gotrue' import { UseCustomQueryOptions } from '@/types' export async function getMfaListFactors() { const { error, data } = await auth.mfa.listFactors() if (error) throw error return data } export type MFAFactor = Factor type CustomMFAListFactorsData = NonNullable type CustomMFAListFactorsError = NonNullable export const useMfaListFactorsQuery = ({ enabled = true, ...options }: UseCustomQueryOptions = {}) => { const userId = useUser()?.id return useQuery({ queryKey: profileKeys.mfaFactors(userId), queryFn: () => getMfaListFactors(), staleTime: 1000 * 60 * 30, enabled, ...options, }) }