Skip to content

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

[FE-4193] fix(studio): show proper names for custom identity providers (#49182)

Alaister Young6073c7a7e70a
diff --git a/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx b/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
index 19feedfb1c1..d767fc21842 100644
--- a/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
+++ b/apps/studio/components/interfaces/SignIn/SignInWithCustom.tsx
@@ -4,18 +4,16 @@ import { Button } from 'ui'
import { BASE_PATH } from '@/lib/constants'
import { captureCriticalError } from '@/lib/error-reporting'
+import { getProviderDisplay } from '@/lib/external-identity-providers'
import { auth, buildPathWithParams } from '@/lib/gotrue'
interface SignInWithCustomProps {
providerName: string
}
-const formatProviderName = (name: string) => {
- return name.replace('custom:', '')
-}
-
export const SignInWithCustom = ({ providerName }: SignInWithCustomProps) => {
const [loading, setLoading] = useState(false)
+ const displayName = getProviderDisplay(providerName).displayName
async function handleCustomSignIn() {
setLoading(true)
@@ -38,7 +36,7 @@ export const SignInWithCustom = ({ providerName }: SignInWithCustomProps) => {
if (error) throw error
} catch (error: any) {
- toast.error(`Failed to sign in via ${providerName}: ${error.message}`)
+ toast.error(`Failed to sign in via ${displayName}: ${error.message}`)
captureCriticalError(error, `sign in via ${providerName}`)
setLoading(false)
}
@@ -46,7 +44,7 @@ export const SignInWithCustom = ({ providerName }: SignInWithCustomProps) => {
return (
<Button block onClick={handleCustomSignIn} size="large" variant="default" loading={loading}>
- Continue with <span className="capitalize">{formatProviderName(providerName)}</span>
+ Continue with {displayName}
</Button>
)
}
diff --git a/apps/studio/lib/external-identity-providers.test.ts b/apps/studio/lib/external-identity-providers.test.ts
index 13413758f43..2b11db6101a 100644
--- a/apps/studio/lib/external-identity-providers.test.ts
+++ b/apps/studio/lib/external-identity-providers.test.ts
@@ -26,6 +26,15 @@ describe('external identity providers', () => {
expect(getProviderDisplay('my_provider').displayName).toBe('my provider')
})
+ test('derives a title-cased name for unregistered custom providers', () => {
+ expect(getProviderDisplay('custom:acme').displayName).toBe('Acme')
+ expect(getProviderDisplay('Custom:Acme').displayName).toBe('Acme')
+ expect(getProviderDisplay('custom:my_provider').displayName).toBe('My Provider')
+ expect(getProviderDisplay('custom:MY_PROVIDER').displayName).toBe('My Provider')
+ // registered custom providers keep their configured display name
+ expect(getProviderDisplay('custom:openai').displayName).toBe('ChatGPT')
+ })
+
test('marks static provider icons as monochrome but not built-in or fallback icons', () => {
expect(getProviderDisplay('github').hasMonochromeIcon).toBe(true)
expect(getProviderDisplay('email').hasMonochromeIcon).toBeUndefined()
diff --git a/apps/studio/lib/external-identity-providers.ts b/apps/studio/lib/external-identity-providers.ts
index a8ab1dcb5ed..436dddf1360 100644
--- a/apps/studio/lib/external-identity-providers.ts
+++ b/apps/studio/lib/external-identity-providers.ts
@@ -69,6 +69,24 @@ export function normalizeIconPath(iconPath: string): string {
return `${BASE_PATH}/${iconPath}`
}
+const CUSTOM_PROVIDER_PREFIX = 'custom:'
+
+/**
+ * Derives a human-readable name from a `custom:*` provider id, e.g. `custom:acme` -> "Acme" and
+ * `custom:my_provider` -> "My Provider". Returns undefined for non-custom providers.
+ */
+function getCustomProviderName(provider: string): string | undefined {
+ if (!provider.toLowerCase().startsWith(CUSTOM_PROVIDER_PREFIX)) return undefined
+
+ return provider
+ .slice(CUSTOM_PROVIDER_PREFIX.length)
+ .replaceAll('_', ' ')
+ .split(' ')
+ .filter(Boolean)
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
+ .join(' ')
+}
+
export function getProviderDisplay(provider: string): IdentityProviderDisplay {
const config = IDENTITY_PROVIDERS.find(
({ id, authProvider }) => provider === id || provider === authProvider
@@ -91,6 +109,17 @@ export function getProviderDisplay(provider: string): IdentityProviderDisplay {
}
}
+ // Unregistered `custom:*` providers (e.g. white-label deployments' own OAuth providers) fall
+ // back to a title-cased name derived from the id: `custom:acme` -> "Acme".
+ const customProviderName = getCustomProviderName(provider)
+ if (customProviderName) {
+ return {
+ id: provider,
+ displayName: customProviderName,
+ iconPath: `${BASE_PATH}/img/icons/saml-icon.svg`,
+ }
+ }
+
return (
BUILT_IN_IDENTITY_PROVIDERS[provider] ?? {
id: provider,