mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 03:45:06 +03:00
* 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.
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { handleError, post } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { keys } from './keys'
|
|
|
|
export type CreateThirdPartyAuthVariables = {
|
|
projectRef: string
|
|
customJwks?: Record<string, never>
|
|
jwksUrl?: string
|
|
oidcIssuerUrl?: string
|
|
}
|
|
|
|
export async function createThirdPartyIntegration({
|
|
projectRef,
|
|
customJwks,
|
|
jwksUrl,
|
|
oidcIssuerUrl,
|
|
}: CreateThirdPartyAuthVariables) {
|
|
const { data, error } = await post(`/v1/projects/{ref}/config/auth/third-party-auth`, {
|
|
params: {
|
|
path: {
|
|
ref: projectRef,
|
|
},
|
|
},
|
|
body: {
|
|
custom_jwks: customJwks,
|
|
jwks_url: jwksUrl,
|
|
oidc_issuer_url: oidcIssuerUrl,
|
|
},
|
|
})
|
|
if (error) handleError(error)
|
|
|
|
return data
|
|
}
|
|
|
|
type ThirdPartyIntegrationCreateData = Awaited<ReturnType<typeof createThirdPartyIntegration>>
|
|
|
|
export const useCreateThirdPartyAuthIntegrationMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<ThirdPartyIntegrationCreateData, ResponseError, CreateThirdPartyAuthVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<ThirdPartyIntegrationCreateData, ResponseError, CreateThirdPartyAuthVariables>(
|
|
(vars) => createThirdPartyIntegration(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 create third party auth integration: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|