mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 23:54:20 +08:00
* Remove the query for temp keys. Remove the query for supabase client. Add a function which creates a supabase client with a temp key. * Add a new query for building the endpoint URL. * Migrate all oAuth queries and mutations to use the new function for creating a Supabase project client. * Use the new queries/mutations in the code. * Use query in refetchInterval for useProjectSettings. * Replace all uses in StorageExplorer with createProjectSupabaseClient.
30 lines
772 B
TypeScript
30 lines
772 B
TypeScript
import { handleError, post } from 'data/fetchers'
|
|
|
|
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
|
|
}
|