mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
* fix(auth-config): invalidate lint cache on update to dismiss stale Performance Advisor warnings * Do the invalidations in parallel. * Fix prettier error. --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import type { components } from 'data/api'
|
|
import { handleError, patch } from 'data/fetchers'
|
|
import { lintKeys } from 'data/lint/keys'
|
|
import type { ResponseError, UseCustomMutationOptions } from 'types'
|
|
import { authKeys } from './keys'
|
|
|
|
export type AuthConfigUpdateVariables = {
|
|
projectRef: string
|
|
config: Partial<components['schemas']['UpdateGoTrueConfigBody']>
|
|
}
|
|
|
|
export async function updateAuthConfig({ projectRef, config }: AuthConfigUpdateVariables) {
|
|
const { data, error } = await patch('/platform/auth/{ref}/config', {
|
|
params: {
|
|
path: { ref: projectRef },
|
|
},
|
|
body: {
|
|
...config,
|
|
},
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type AuthConfigUpdateData = Awaited<ReturnType<typeof updateAuthConfig>>
|
|
|
|
export const useAuthConfigUpdateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<AuthConfigUpdateData, ResponseError, AuthConfigUpdateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<AuthConfigUpdateData, ResponseError, AuthConfigUpdateVariables>({
|
|
mutationFn: (vars) => updateAuthConfig(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: authKeys.authConfig(projectRef) }),
|
|
queryClient.invalidateQueries({ queryKey: lintKeys.lint(projectRef) }),
|
|
])
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to update auth configuration: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|