Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: useProjectSettings refreshInterval to wait for service_api_keys data

phamhieu00f88bb69d09
diff --git a/studio/hooks/queries/useProjectSettings.ts b/studio/hooks/queries/useProjectSettings.ts
index 833bb17f489..e97eba1a0c9 100644
--- a/studio/hooks/queries/useProjectSettings.ts
+++ b/studio/hooks/queries/useProjectSettings.ts
@@ -4,7 +4,18 @@ import useSWR from 'swr'
export function useProjectSettings(ref?: string) {
const url = `${API_URL}/props/project/${ref}/settings`
- const { data, error } = useSWR<any>(ref ? url : null, get)
+ const { data, error } = useSWR<any>(ref ? url : null, get, {
+ /**
+ * on project creation, the service_api_keys will be populated with a delay
+ * check for data.services.service_api_keys, return a valid refresh interval if it's empty
+ */
+ refreshInterval: function (data: any) {
+ const apiService = (data?.services ?? []).find((x: any) => x.app.id == DEFAULT_API_SERVICE_ID)
+ const apiKeys = apiService?.service_api_keys ?? []
+ const interval = apiKeys.length === 0 ? 2000 : 0
+ return interval
+ },
+ })
const anyError = data?.error || error
return {
@@ -15,3 +26,5 @@ export function useProjectSettings(ref?: string) {
isError: !!anyError,
}
}
+
+const DEFAULT_API_SERVICE_ID = 1