mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 09:50:33 -04:00
30 lines
774 B
TypeScript
30 lines
774 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
|
|
}
|