Files
supabase/apps/studio/data/api-keys/temp-api-keys-query.ts
Joshen Lim 7a35ad3081 Bump temp API key expiry to an hour just for realtime inspector (#37896)
* Bump temp API key expiry to an hour just for realtime inspector

* Refresh temp api token whenever starting a refresh listen session in realtime inspector if current token in realtime config is a temp key
2025-08-14 15:24:30 +07:00

31 lines
862 B
TypeScript

import { handleError, post } from 'data/fetchers'
interface getTemporaryAPIKeyVariables {
projectRef?: string
/** In seconds, max: 3600 (an hour) */
expiry?: number
}
// [Joshen] This one specifically shouldn't need a useQuery hook since the expiry is meant to be short lived
// Used in storage explorer and realtime inspector.
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
}