mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 03:15:06 +03:00
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { orgSSOKeys } from './keys'
|
|
import type { components } from '@/data/api'
|
|
import { handleError, post } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type SSOConfigCreateVariables = {
|
|
slug: string
|
|
config: components['schemas']['CreateSSOProviderBody']
|
|
}
|
|
|
|
export async function createSSOConfig({ slug, config }: SSOConfigCreateVariables) {
|
|
const { data, error } = await post('/platform/organizations/{slug}/sso', {
|
|
params: { path: { slug } },
|
|
body: config,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type SSOConfigCreateData = Awaited<ReturnType<typeof createSSOConfig>>
|
|
|
|
export const useSSOConfigCreateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<SSOConfigCreateData, ResponseError, SSOConfigCreateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<SSOConfigCreateData, ResponseError, SSOConfigCreateVariables>({
|
|
mutationFn: (vars) => createSSOConfig(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { slug } = variables
|
|
await queryClient.invalidateQueries({ queryKey: orgSSOKeys.orgSSOConfig(slug) })
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to create SSO configuration: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|