{"record":{"id":"e4d3696c6af019c2","repo":"supabase/supabase","slug":"projectref-is-required-e4d369","errorCode":null,"errorMessage":"projectRef is required","messagePattern":"projectRef is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/studio/data/api-keys/api-keys-query.ts","lineNumber":55,"sourceCode":"  hash?: string\n  id: string\n  inserted_at: string\n  name: string\n  prefix?: string\n  secret_jwt_template?: { role: string } | null\n  type: 'publishable'\n  updated_at?: string\n}\n\ninterface APIKeysVariables {\n  projectRef?: string\n  reveal?: boolean\n}\n\nexport type APIKey = LegacyKeys | SecretKeys | PublishableKeys\n\nasync function getAPIKeys({ projectRef, reveal }: APIKeysVariables, signal?: AbortSignal) {\n  if (!projectRef) throw new Error('projectRef is required')\n\n  const { data, error } = await get(`/v1/projects/{ref}/api-keys`, {\n    params: { path: { ref: projectRef }, query: { reveal } },\n    signal,\n  })\n\n  if (error) handleError(error)\n\n  // [Jonny]: Overriding the types here since some stuff is not actually nullable or optional\n  return data as unknown as APIKey[]\n}\n\nexport type APIKeysData = Awaited<ReturnType<typeof getAPIKeys>>\n\nexport const useAPIKeysQuery = <TData = APIKeysData>(\n  { projectRef, reveal = false }: APIKeysVariables,\n  { enabled = true, ...options }: UseCustomQueryOptions<APIKeysData, ResponseError, TData> = {}\n) => {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/supabase/supabase/blob/beee91b9c2228dd57302dec75c733baaa84ab543/apps/studio/data/api-keys/api-keys-query.ts#L37-L73","documentation":"Thrown by getAPIKeys() when projectRef is falsy, before GET /v1/projects/{ref}/api-keys (the list endpoint). projectRef supplies the `{ref}` path segment. reveal is an optional query param controlling whether secret values are returned; it is not guarded. Returns APIKey[] (union of legacy/secret/publishable keys).","triggerScenarios":"useAPIKeysQuery runs before the project ref is available, or with enabled forced true while projectRef is undefined; the API-keys list page mounts before the project context hydrates.","commonSituations":"The API-keys settings page loads from a deep link before the selected project resolves; the page is rendered outside a project scope; a project switch leaves the query briefly enabled with no ref; test fixtures omit projectRef.","solutions":["Gate the query on `enabled={!!projectRef}`.","Resolve the selected project before rendering the API-keys list.","When calling getAPIKeys directly, supply a non-empty projectRef.","Tighten projectRef to required `string` in APIKeysVariables at the hook boundary."],"exampleFix":"// before\nuseAPIKeysQuery({ projectRef, reveal }, { enabled: true })\n// after\nuseAPIKeysQuery({ projectRef, reveal }, { enabled: !!projectRef })","handlingStrategy":"validation","validationCode":"const enabled = !!projectRef","typeGuard":"function hasAPIKeysRef(v: APIKeysVariables): v is APIKeysVariables & { projectRef: string } {\n  return !!v.projectRef\n}","tryCatchPattern":null,"preventionTips":["Gate useAPIKeysQuery on `enabled={!!projectRef}`.","Resolve the selected project before rendering the API-keys list.","Make projectRef required in APIKeysVariables at the hook boundary.","Pass a non-empty projectRef in direct fetcher calls."],"tags":["validation","parameter-validation","projectref","api-keys","react-query","typescript"],"backgroundTag":null,"analyzedSha":"beee91b9c2228dd57302dec75c733baaa84ab543","analyzedAt":"2026-08-12T06:51:48.935Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}