mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## Problem The Performance Advisor warning "Auth Absolute Connection Management Strategy" persists after switching from "Absolute" to "Percentage" allocation strategy, even after project restart. PR #41652 added cache invalidation but the frontend doesn't immediately refetch, so stale lint data may be displayed until the next natural refetch occurs. ## Solution Force an immediate refetch of lint data after invalidating the cache. This ensures the backend re-evaluates the `auth_db_connections_absolute` lint with the updated `DB_MAX_POOL_SIZE_UNIT` configuration value. ## Changes - Added `refetchQueries` call after cache invalidation in `useAuthConfigUpdateMutation` - Uses `type: 'active'` to only refetch active queries (React Query best practice) ## Related - Extends: https://github.com/supabase/supabase/pull/41652 - Closes: https://github.com/supabase/supabase/issues/41619 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved data consistency by ensuring validation information is automatically refreshed following authentication configuration updates. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
65 lines
1.9 KiB
TypeScript
65 lines
1.9 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 queryClient.refetchQueries({
|
|
queryKey: lintKeys.lint(projectRef),
|
|
type: 'active',
|
|
})
|
|
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,
|
|
})
|
|
}
|