Skip to content

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

feat: button to enable custom providers (#43985)

Cemal Kılıçd566a2a0a6aa
diff --git a/apps/studio/components/interfaces/Auth/CustomAuthProviders/CustomAuthProvidersList.tsx b/apps/studio/components/interfaces/Auth/CustomAuthProviders/CustomAuthProvidersList.tsx
index 0ad62b2ea64..f6915406712 100644
--- a/apps/studio/components/interfaces/Auth/CustomAuthProviders/CustomAuthProvidersList.tsx
+++ b/apps/studio/components/interfaces/Auth/CustomAuthProviders/CustomAuthProvidersList.tsx
@@ -2,6 +2,7 @@ import { useParams } from 'common'
import { Edit, MoreVertical, Plus, Search, Trash, X } from 'lucide-react'
import { parseAsBoolean, parseAsStringLiteral, useQueryState } from 'nuqs'
import { useEffect, useMemo, useState } from 'react'
+import { useQueryClient } from '@tanstack/react-query'
import {
Badge,
Button,
@@ -36,8 +37,11 @@ import AlertError from '@/components/ui/AlertError'
import { FilterPopover } from '@/components/ui/FilterPopover'
import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton'
import { useAuthConfigQuery } from '@/data/auth/auth-config-query'
+import { useAuthConfigUpdateMutation } from '@/data/auth/auth-config-update-mutation'
import { useOAuthCustomProvidersQuery } from '@/data/oauth-custom-providers/oauth-custom-providers-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
+import { toast } from 'sonner'
+import { Admonition } from 'ui-patterns/admonition'
const CUSTOM_PROVIDERS_SORT_VALUES = [
'name:asc',
@@ -87,6 +91,23 @@ export const CustomAuthProvidersList = () => {
const isCustomProvidersEnabled = !!authConfig?.CUSTOM_OAUTH_ENABLED
const providerLimit = authConfig?.CUSTOM_OAUTH_MAX_PROVIDERS || 0
+ const queryClient = useQueryClient()
+ const { mutate: updateAuthConfig, isPending: isEnabling } = useAuthConfigUpdateMutation({
+ onSuccess: () => {
+ toast.success('Custom providers have been enabled')
+ // Invalidate and refetch custom providers query so it retries after enabling
+ queryClient.invalidateQueries({
+ queryKey: ['projects', projectRef, 'oauth-custom-providers'],
+ })
+ },
+ })
+
+ const handleEnableCustomProviders = () => {
+ if (projectRef) {
+ updateAuthConfig({ projectRef, config: { CUSTOM_OAUTH_ENABLED: true } })
+ }
+ }
+
const [selectedProviderToEdit, setSelectedProviderToEdit] = useState<string | null>(null)
const [selectedProviderToDelete, setSelectedProviderToDelete] = useState<string | null>(null)
const [filteredProviderTypes, setFilteredProviderTypes] = useState<string[]>([])
@@ -201,7 +222,44 @@ export const CustomAuthProvidersList = () => {
return <GenericSkeletonLoader />
}
+ if (!isCustomProvidersEnabled) {
+ return (
+ <Admonition
+ type="default"
+ title="Custom providers are not enabled"
+ description="Enable custom OAuth/OIDC providers to configure your own identity providers for authentication."
+ >
+ <Button
+ type="primary"
+ loading={isEnabling}
+ disabled={isEnabling}
+ onClick={handleEnableCustomProviders}
+ >
+ Enable Custom Providers
+ </Button>
+ </Admonition>
+ )
+ }
+
if (isError) {
+ if (error?.message?.includes('Custom providers are not enabled')) {
+ return (
+ <Admonition
+ type="default"
+ title="Custom providers are not enabled"
+ description="Enable custom OAuth/OIDC providers to configure your own identity providers for authentication."
+ >
+ <Button
+ type="primary"
+ loading={isEnabling}
+ disabled={isEnabling}
+ onClick={handleEnableCustomProviders}
+ >
+ Enable Custom Providers
+ </Button>
+ </Admonition>
+ )
+ }
return <AlertError error={error} subject="Failed to retrieve Custom Auth Providers" />
}
@@ -267,7 +325,18 @@ export const CustomAuthProvidersList = () => {
className="text-xs flex flex-col gap-y-2 bg-alternative items-start"
>
{!isCustomProvidersEnabled ? (
- 'Custom providers are not enabled for this project. Please contact support to enable this feature.'
+ <div className="flex flex-col gap-y-2">
+ <p>Custom providers are not enabled for this project.</p>
+ <Button
+ type="primary"
+ size="tiny"
+ loading={isEnabling}
+ disabled={isEnabling}
+ onClick={handleEnableCustomProviders}
+ >
+ Enable Custom Providers
+ </Button>
+ </div>
) : (
<>
<p>You've reached the limit of {providerLimit} providers for your plan.</p>
diff --git a/apps/studio/data/oauth-custom-providers/oauth-custom-providers-query.ts b/apps/studio/data/oauth-custom-providers/oauth-custom-providers-query.ts
index 0bd043c0155..833af50369d 100644
--- a/apps/studio/data/oauth-custom-providers/oauth-custom-providers-query.ts
+++ b/apps/studio/data/oauth-custom-providers/oauth-custom-providers-query.ts
@@ -27,12 +27,10 @@ export async function getOAuthCustomProviders({
if (error) {
let newError = error
- console.log(newError)
- if (
- newError.message.startsWith(
- 'AuthUnknownError: JSON.parse: unexpected non-whitespace character'
- )
- ) {
+ // Non-JSON responses from the API indicate custom providers aren't enabled.
+ // Different browsers/SDK versions produce different JSON parse error messages,
+ // so we check broadly for JSON parse indicators.
+ if (/JSON\.parse|Unexpected token|unexpected.*character/.test(newError.message)) {
newError = new AuthError('Custom providers are not enabled for this project')
}
handleError(newError)