Skip to content

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

Fix Auth OAuth apps request error if oauth server has not been configured (#41870)

Joshen Lim2e7b968b1c81
diff --git a/apps/studio/components/interfaces/Auth/OAuthApps/OAuthAppsList.tsx b/apps/studio/components/interfaces/Auth/OAuthApps/OAuthAppsList.tsx
index 73be6ff767d..2d31a8dcbe7 100644
--- a/apps/studio/components/interfaces/Auth/OAuthApps/OAuthAppsList.tsx
+++ b/apps/studio/components/interfaces/Auth/OAuthApps/OAuthAppsList.tsx
@@ -71,12 +71,7 @@ export const OAuthAppsList = () => {
const [filteredClientTypes, setFilteredClientTypes] = useState<string[]>([])
const deletingOAuthAppIdRef = useRef<string | null>(null)
- const {
- data,
- isPending: isLoading,
- isError,
- error,
- } = useOAuthServerAppsQuery({ projectRef }, { enabled: isOAuthServerEnabled })
+ const { data, isPending: isLoading, isError, error } = useOAuthServerAppsQuery({ projectRef })
const { mutateAsync: regenerateSecret, isPending: isRegenerating } =
useOAuthServerAppRegenerateSecretMutation({
@@ -89,7 +84,7 @@ export const OAuthAppsList = () => {
const { data: endpointData } = useProjectEndpointQuery({ projectRef })
- const oAuthApps = data?.clients || []
+ const oAuthApps = useMemo(() => data?.clients || [], [data])
const [showCreateSheet, setShowCreateSheet] = useQueryState(
'new',
diff --git a/apps/studio/components/interfaces/Auth/OAuthApps/OAuthServerSettingsForm.tsx b/apps/studio/components/interfaces/Auth/OAuthApps/OAuthServerSettingsForm.tsx
index 6a46e090259..7f59d1461f9 100644
--- a/apps/studio/components/interfaces/Auth/OAuthApps/OAuthServerSettingsForm.tsx
+++ b/apps/studio/components/interfaces/Auth/OAuthApps/OAuthServerSettingsForm.tsx
@@ -72,11 +72,13 @@ interface OAuthServerSettings {
export const OAuthServerSettingsForm = () => {
const { ref: projectRef } = useParams()
+
const {
data: authConfig,
isPending: isAuthConfigLoading,
isSuccess,
} = useAuthConfigQuery({ projectRef })
+
const { mutate: updateAuthConfig, isPending } = useAuthConfigUpdateMutation({
onSuccess: () => {
toast.success('OAuth server settings updated successfully')
diff --git a/apps/studio/data/oauth-server-apps/oauth-server-apps-query.ts b/apps/studio/data/oauth-server-apps/oauth-server-apps-query.ts
index 4fc560c0037..83e1962b335 100644
--- a/apps/studio/data/oauth-server-apps/oauth-server-apps-query.ts
+++ b/apps/studio/data/oauth-server-apps/oauth-server-apps-query.ts
@@ -5,6 +5,7 @@ import { useProjectEndpointQuery } from 'data/config/project-endpoint-query'
import { handleError } from 'data/fetchers'
import { createProjectSupabaseClient } from 'lib/project-supabase-client'
import type { ResponseError, UseCustomQueryOptions } from 'types'
+import { useAuthConfigQuery } from '../auth/auth-config-query'
import { oauthServerAppKeys } from './keys'
export type OAuthServerAppsVariables = {
@@ -45,15 +46,21 @@ export const useOAuthServerAppsQuery = <TData = OAuthServerAppsData>(
...options
}: UseCustomQueryOptions<OAuthServerAppsData, OAuthServerAppsError, TData> = {}
) => {
- const { data: endpointData } = useProjectEndpointQuery({
- projectRef,
- })
+ const { data: endpointData } = useProjectEndpointQuery({ projectRef })
const clientEndpoint = endpointData?.endpoint
+ const { data: authConfig, isSuccess: isSuccessConfig } = useAuthConfigQuery({ projectRef })
+ const isOAuthServerEnabled = !!authConfig?.OAUTH_SERVER_ENABLED
+
return useQuery<OAuthServerAppsData, OAuthServerAppsError, TData>({
queryKey: oauthServerAppKeys.list(projectRef, clientEndpoint),
queryFn: () => getOAuthServerApps({ projectRef, clientEndpoint }),
- enabled: enabled && typeof projectRef !== 'undefined' && !!clientEndpoint,
+ enabled:
+ enabled &&
+ typeof projectRef !== 'undefined' &&
+ !!clientEndpoint &&
+ isSuccessConfig &&
+ isOAuthServerEnabled,
...options,
})
}