Files
supabase/apps/studio/data/auth/user-delete-mfa-factors-mutation.ts
Joshen LimandAlaister Young 0c81551110 RQ convert mutateAsync calls to mutate where possible, otherwise add try finally blocks (#26737)
* RQ convert mutateAsync calls to mutate where possible, otherwise add try finally blocks

* Skip eligibility query if project status is coming up

* Small UI update to replicas side panel

* Update apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>

* Add error handling in CIDR

* Prettier lint

---------

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
2024-05-24 16:58:49 +08:00

47 lines
1.4 KiB
TypeScript

import { useMutation, UseMutationOptions } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { delete_ } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import type { ResponseError } from 'types'
export type UserDeleteMFAFactorsVariables = {
projectRef: string
userId: string
}
export async function deleteMFAFactors({ projectRef, userId }: UserDeleteMFAFactorsVariables) {
const response = await delete_(`${API_URL}/auth/${projectRef}/users/${userId}/factors`)
if (response.error) throw response.error
return response
}
type UserDeleteMFAFactorsData = Awaited<ReturnType<typeof deleteMFAFactors>>
export const useUserDeleteMFAFactorsMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<UserDeleteMFAFactorsData, ResponseError, UserDeleteMFAFactorsVariables>,
'mutationFn'
> = {}) => {
return useMutation<UserDeleteMFAFactorsData, ResponseError, UserDeleteMFAFactorsVariables>(
(vars) => deleteMFAFactors(vars),
{
async onSuccess(data, variables, context) {
// [Joshen] If we need to invalidate any queries
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to delete the user's MFA factors: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
}
)
}