mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
* feat: allow disabling and re-enabling of `anon` and `service_role` * Cleanup the RQ hooks. * Restructure the enable/disable alert in API keys. * Minor cleanups. * Minor fixes. * Fix a type error. --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
import { apiKeysKeys } from './keys'
|
|
|
|
interface LegacyAPIKeysStatusVariables {
|
|
projectRef?: string
|
|
}
|
|
|
|
async function getLegacyAPIKeysStatus(
|
|
{ projectRef }: LegacyAPIKeysStatusVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get(`/v1/projects/{ref}/api-keys/legacy`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
type LegacyAPIKeysStatusData = Awaited<ReturnType<typeof getLegacyAPIKeysStatus>>
|
|
|
|
export const useLegacyAPIKeysStatusQuery = <TData = LegacyAPIKeysStatusData>(
|
|
{ projectRef }: LegacyAPIKeysStatusVariables,
|
|
{ ...options }: UseQueryOptions<LegacyAPIKeysStatusData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<LegacyAPIKeysStatusData, ResponseError, TData>(
|
|
apiKeysKeys.status(projectRef),
|
|
({ signal }) => getLegacyAPIKeysStatus({ projectRef }, signal),
|
|
{
|
|
enabled: !!projectRef,
|
|
...options,
|
|
}
|
|
)
|