mirror of
https://github.com/supabase/supabase.git
synced 2026-05-26 21:53:19 +08:00
* Support updating email address for email identity * Support unlinking identity * Deprecate AccountInformation component * Invalidate identities after unlinking * Address feedback * Smol * Fix type issues * Update toast message * Set up email change pending badge * Fix * Address feedback * Resolve ts-expect-errors * Fix TS issues + Fix GH icon on light mode + Address feedback
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
|
|
import { apiKeysKeys } from './keys'
|
|
|
|
type LegacyKeys = {
|
|
api_key: string
|
|
description?: string | null
|
|
hash?: string | null
|
|
id?: string | null
|
|
inserted_at?: string | null
|
|
name: string
|
|
prefix?: string | null
|
|
secret_jwt_template?: { role: string } | null
|
|
type: 'legacy' | null
|
|
updated_at?: string | null
|
|
}
|
|
|
|
type SecretKeys = {
|
|
api_key: string
|
|
description?: string
|
|
hash: string
|
|
id: string
|
|
inserted_at: string
|
|
name: string
|
|
prefix: string
|
|
secret_jwt_template: { role: string }
|
|
type: 'secret'
|
|
updated_at?: string
|
|
}
|
|
|
|
type PublishableKeys = {
|
|
api_key: string
|
|
description?: string
|
|
hash?: string
|
|
id: string
|
|
inserted_at: string
|
|
name: string
|
|
prefix?: string
|
|
secret_jwt_template?: { role: string } | null
|
|
type: 'publishable'
|
|
updated_at?: string
|
|
}
|
|
|
|
export interface APIKeysVariables {
|
|
projectRef?: string
|
|
reveal: boolean
|
|
}
|
|
|
|
export async function getAPIKeys({ projectRef, reveal }: APIKeysVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await get(`/v1/projects/{ref}/api-keys`, {
|
|
params: { path: { ref: projectRef }, query: { reveal } },
|
|
signal,
|
|
})
|
|
|
|
if (error) {
|
|
handleError(error)
|
|
}
|
|
|
|
// [Jonny]: Overriding the types here since some stuff is not actually nullable or optional
|
|
return data as unknown as (LegacyKeys | SecretKeys | PublishableKeys)[]
|
|
}
|
|
|
|
export type APIKeysData = Awaited<ReturnType<typeof getAPIKeys>>
|
|
|
|
export const useAPIKeysQuery = <TData = APIKeysData>(
|
|
{ projectRef, reveal }: APIKeysVariables,
|
|
{ enabled, ...options }: UseQueryOptions<APIKeysData, ResponseError, TData> = {}
|
|
) =>
|
|
useQuery<APIKeysData, ResponseError, TData>(
|
|
apiKeysKeys.list(projectRef),
|
|
({ signal }) => getAPIKeys({ projectRef, reveal }, signal),
|
|
{
|
|
enabled: enabled && !!projectRef,
|
|
...options,
|
|
}
|
|
)
|