Files
supabase/apps/studio/data/third-party-auth/integration-delete-mutation.ts
Ivan Vasilov 9ac44f5985 feat: Add Third Party Auth settings (#27564)
* Add queries and mutations for third party auth.

* Show the ThirdPartyAuth form in the auth settings.

* Minor fixes to the mutations.

* Add a comment for TODO.

* Add all components for third party auth.

* Minor fixes.

* Update the firebase icons.

* Update the api-types.

* Fix the barrel file imports.

* Make the sheets more intuitive.

* Add a dialog for adding RLS policies for the firebase integration.

* Hide the 3rd party auth section behind a form.

* Fix a type error.

* Update the wording on the Add RLS policy dialog.

* Replace the sheets with dialogs.

* Add fixes for the comments on github.

* Minor fixes.

* Fix a type error.

* Make the delete integration awaitable.
2024-07-25 11:07:09 +02:00

64 lines
1.7 KiB
TypeScript

import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import toast from 'react-hot-toast'
import { del, handleError } from 'data/fetchers'
import type { ResponseError } from 'types'
import { keys } from './keys'
export type DeleteThirdPartyAuthIntegrationVariables = {
projectRef: string
tpaId: string
}
export async function deleteThirdPartyIntegration({
projectRef,
tpaId,
}: DeleteThirdPartyAuthIntegrationVariables) {
const { data, error } = await del('/v1/projects/{ref}/config/auth/third-party-auth/{tpa_id}', {
params: {
path: {
ref: projectRef,
tpa_id: tpaId,
},
},
})
if (error) handleError(error)
return data
}
type DeleteThirdPartyAuthIntegrationData = Awaited<ReturnType<typeof deleteThirdPartyIntegration>>
export const useDeleteThirdPartyAuthIntegrationMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<
DeleteThirdPartyAuthIntegrationData,
ResponseError,
DeleteThirdPartyAuthIntegrationVariables
>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<
DeleteThirdPartyAuthIntegrationData,
ResponseError,
DeleteThirdPartyAuthIntegrationVariables
>((vars) => deleteThirdPartyIntegration(vars), {
async onSuccess(data, variables, context) {
const { projectRef } = variables
await queryClient.invalidateQueries(keys.integrations(projectRef))
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to delete third party auth integration: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}