Files
supabase/apps/studio/data/api-keys/legacy-api-keys-status-query.ts
Stojan DimitrovskiandIvan Vasilov 7c3f79578e feat: allow disabling and re-enabling of anon and service_role (#36395)
* 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>
2025-06-16 17:46:34 +02:00

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,
}
)