mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
* oAuth clients index layout * oAuth apps crud * is public * add user count and client secret generation and management * scaffold oauth server settings * improve oauth server enablement / disablement * show cover when oAuth server is disabled * fix update panel update button * add site url and authorization path settings values * move oauth server to it's own nav item * remove unneeded oauth server settings * let the user disactivate oauth server even after creating oauth apps * better delete button * cleanup * fix typecheck * test endpoints * add EnableOAuth21 feature flag * update OAUTH_SERVER_ auth config api * load OAUTH_SERVER_ENABLED in oauth list * Update the api.d.ts. Remove the custom versions of supa libs. * Add query for getTemporaryAPIKey. * Add a hook for initializing a supabase client. * Add hooks for oAuth Server apps. * Regenerate pnpm-lock.yaml. * Revert updates to the platform.d.ts. Not needed for this PR. * Migrate all code to use the new hooks. * Try to integrate the mutations and fix some of the sheet and dialogs. * improve default and saving states * fix oauth app form validation * unify components into CreateOrUpdateOAuthAppModal * create or update oauth app * Update the OAuth Server page. * Remove extra files. * Minor various fixes. * More fixes to the creation of oauth apps. * Bump the libs to fix a DELETE oauth app error. * Clean up the scope feature. * Move the feature flag in the auth layout. * Bunch of smaller fixes. * Regenerate pnpm-lock. * Revert SidePanel and CardDescription changes. * Add confirm dialog for regenerating secret. --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
|
|
|
|
import { handleError, post } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { apiKeysKeys } from './keys'
|
|
|
|
interface getTemporaryAPIKeyVariables {
|
|
projectRef?: string
|
|
/** In seconds, max: 3600 (an hour) */
|
|
expiry?: number
|
|
}
|
|
|
|
// Used in storage explorer, realtime inspector and OAuth Server apps.
|
|
export async function getTemporaryAPIKey(
|
|
{ projectRef, expiry = 300 }: getTemporaryAPIKeyVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { data, error } = await post('/platform/projects/{ref}/api-keys/temporary', {
|
|
params: {
|
|
path: { ref: projectRef },
|
|
query: {
|
|
authorization_exp: expiry.toString(),
|
|
claims: JSON.stringify({ role: 'service_role' }),
|
|
},
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type TemporaryAPIKeyData = Awaited<ReturnType<typeof getTemporaryAPIKey>>
|
|
|
|
export const useTemporaryAPIKeyQuery = <TData = TemporaryAPIKeyData>(
|
|
{ projectRef, expiry = 300 }: getTemporaryAPIKeyVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<TemporaryAPIKeyData, ResponseError, TData> = {}
|
|
) => {
|
|
return useQuery<TemporaryAPIKeyData, ResponseError, TData>({
|
|
queryKey: apiKeysKeys.temporary(projectRef),
|
|
queryFn: ({ signal }) => getTemporaryAPIKey({ projectRef, expiry }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
refetchInterval: expiry * 1000, // convert to ms
|
|
...options,
|
|
})
|
|
}
|