mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 06:09:08 +03:00
* fix(studio): early fail query when x-connection-encrypted is invalid * fix(studio): uniformize readDatabase and projectDetails connString handling * chore: update api types * chore: add connectionString null option * fix: only enforce x-connection-encrypted on platform * chore: refactor connString check in a single point * chore: fix guard logic * chore: fix pgMetaGuard * chore: fix types
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { Query } from '@supabase/pg-meta/src/query'
|
|
import { executeSql } from 'data/sql/execute-sql-query'
|
|
import type { ResponseError } from 'types'
|
|
import { vaultSecretsKeys } from './keys'
|
|
|
|
export type VaultSecretDeleteVariables = {
|
|
projectRef: string
|
|
connectionString?: string | null
|
|
id: string
|
|
}
|
|
|
|
export async function deleteVaultSecret({
|
|
projectRef,
|
|
connectionString,
|
|
id,
|
|
}: VaultSecretDeleteVariables) {
|
|
const sql = new Query().from('secrets', 'vault').delete().match({ id }).toSql()
|
|
const { result } = await executeSql({ projectRef, connectionString, sql })
|
|
return result
|
|
}
|
|
|
|
type VaultSecretDeleteData = Awaited<ReturnType<typeof deleteVaultSecret>>
|
|
|
|
export const useVaultSecretDeleteMutation = ({
|
|
onError,
|
|
onSuccess,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<VaultSecretDeleteData, ResponseError, VaultSecretDeleteVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<VaultSecretDeleteData, ResponseError, VaultSecretDeleteVariables>(
|
|
(vars) => deleteVaultSecret(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries(vaultSecretsKeys.list(projectRef))
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to delete key: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|