The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
import { useMutation, useQueryClient } from '@tanstack/react-query'
import type { operations } from 'api-types'
import { toast } from 'sonner'
import { orgSSOKeys } from './keys'
import { handleError, post } from '@/data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from '@/types'
type CreateSSOProviderBody =
operations['SSOProvidersController_createSSOProvider']['requestBody']['content']['application/json']
export type SSOConfigCreateVariables = {
slug: string
config: 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,
})
}