Files
supabase/apps/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx
T
Danny WhiteandJoshen Lim a31ca2bad0 fix(ui): make brand text readable across themes (#49871)
## What kind of change does this PR introduce?

Bug fix and design-system update. Resolves DEPR-316.

Follow-up rename (`text-brand` → `text-primary`) is in a dedicated PR
(https://github.com/supabase/supabase/pull/50564) stacked on this one.

## What is the current behavior?

`text-brand` resolves to the canonical bright brand green in places that
need readable text, which fails WCAG AA on light surfaces. A separate
`text-brand-display` token adds another green for large type.

## What is the new behavior?

- `text-brand` maps to accessible `--primary` (light mode darkened to
meet ~4.5:1 AA)
- `--hue` / `--primary-hue` aligned to 157.5
- `text-brand-display` removed; former display callsites use
`text-brand`
- Bright fills/borders stay on `brand-default`
- Design-system colour and typography docs updated

| Before | After |
| --- | --- |
| <img width="514" height="112" alt="CleanShot 2026-09-02 at 11 13
09@2x"
src="https://github.com/user-attachments/assets/4e0138a9-a32d-4e4c-a426-90736706e1e7"
/> | <img width="512" height="138" alt="CleanShot 2026-09-21 at 11 42
05@2x"
src="https://github.com/user-attachments/assets/164cc5b1-a0c5-4e93-95f1-80016641a114"
/> |
| <img width="864" height="266" alt="CleanShot 2026-09-02 at 11 13
53@2x"
src="https://github.com/user-attachments/assets/3c1ca53f-bf9e-431e-bc15-816b4a275b8e"
/> | <img width="882" height="248" alt="CleanShot 2026-09-21 at 11 41
37@2x"
src="https://github.com/user-attachments/assets/24828e7b-ed6b-44cb-b9dc-becc3398bdfc"
/> |
| <img width="782" height="692" alt="CleanShot 2026-09-02 at 11 16
30@2x"
src="https://github.com/user-attachments/assets/fc871977-77bc-47fb-9e0e-9284e0ecd5cc"
/> | <img width="730" height="690" alt="CleanShot 2026-09-21 at 11 42
52@2x"
src="https://github.com/user-attachments/assets/bf479515-d5f9-471e-b82d-f097c0f4b56c"
/> |
| <img width="480" height="306" alt="CleanShot 2026-09-02 at 11 18
53@2x"
src="https://github.com/user-attachments/assets/03f341f4-f02e-44f8-a2b2-8c31670d0427"
/> | <img width="470" height="300" alt="CleanShot 2026-09-21 at 11 43
19@2x"
src="https://github.com/user-attachments/assets/9df18217-d5e6-48b8-ba0b-579d2664b94b"
/> |
| <img width="960" height="300" alt="CleanShot 2026-09-02 at 11 32
04@2x"
src="https://github.com/user-attachments/assets/6b1d9373-7a71-4247-81ff-26441604b09d"
/> | <img width="980" height="306" alt="CleanShot 2026-09-21 at 11 44
13@2x"
src="https://github.com/user-attachments/assets/41ad4784-02ec-4b29-b860-32af9fa79aa8"
/> |
| <img width="924" height="214" alt="CleanShot 2026-09-02 at 11 34
44@2x"
src="https://github.com/user-attachments/assets/1de661fe-c7b6-499b-a94f-e4737436ec79"
/> | <img width="752" height="162" alt="CleanShot 2026-09-21 at 11 44
56@2x"
src="https://github.com/user-attachments/assets/1811890f-0660-4445-84e9-447720954fa1"
/> |

## To test

Test each callsite **in light mode** (dark mode is largely unchanged).

### WWW

-
[Homepage](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/):
“Scale to millions” uses readable brand text (display token is gone)
-
[Careers](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/careers):
small “Careers” eyebrow readable; green dividers stay bright
`brand-default`
-
[Contact](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/contact-us):
email / policy links use readable brand text
-
[Regions](https://zone-www-dot-com-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/regions):
“Ask about early access to BYOC” readable

### Docs

- [Docs
homepage](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs):
“DOCS” wordmark and resource links readable
- [Database
overview](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/guides/database/overview):
nav / footer brand links readable
- [JavaScript
reference](https://docs-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/reference/javascript/introduction):
active sidebar treatment readable

### Design system

-
[Typography](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/typography):
documents `text-brand` only (no display)
- [Colour
usage](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/docs/color-usage):
`text-brand` vs `bg-brand-default`
- [Design-system
homepage](https://design-system-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/):
brand text examples across themes

### Studio

- [Auth
providers](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/auth/providers):
enabled provider badge text readable; status dot stays bright
- [Database
policies](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/database/policies?new=true):
template hover text more legible
- [Database
connections](https://studio-staging-git-dnywh-depr-316-brand-text-tokens-supabase.vercel.app/dashboard/project/_/observability/connections):
“Live” status readable; animated dot stays bright green

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-09-22 10:07:28 +10:00

317 lines
11 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { Check } from 'lucide-react'
import { useTheme } from 'next-themes'
import { useQueryState } from 'nuqs'
import { useCallback, useEffect, useId, useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import ReactMarkdown from 'react-markdown'
import { toast } from 'sonner'
import {
Button,
Form,
Sheet,
SheetContent,
SheetFooter,
SheetHeader,
SheetSection,
SheetTitle,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { NO_REQUIRED_CHARACTERS } from '../Auth.constants'
import { AuthAlert } from './AuthAlert'
import type { Provider } from './AuthProvidersForm.types'
import FormField from './FormField'
import { Markdown } from '@/components/interfaces/Markdown'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { DocsButton } from '@/components/ui/DocsButton'
import { ResourceItem } from '@/components/ui/Resource/ResourceItem'
import type { components } from '@/data/api'
import { useAuthConfigUpdateMutation } from '@/data/auth/auth-config-update-mutation'
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
import { useHasEntitlementAccess } from '@/hooks/misc/useCheckEntitlements'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { BASE_PATH } from '@/lib/constants'
interface ProviderFormProps {
config: components['schemas']['GoTrueConfigResponse']
provider: Provider
isActive: boolean
}
const doubleNegativeKeys = ['SMS_AUTOCONFIRM']
export const ProviderForm = ({ config, provider, isActive }: ProviderFormProps) => {
const { resolvedTheme } = useTheme()
const { ref: projectRef } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
const [urlProvider, setUrlProvider] = useQueryState('provider', { defaultValue: '' })
const [open, setOpen] = useState(false)
const { mutate: updateAuthConfig, isPending: isUpdatingConfig } = useAuthConfigUpdateMutation()
const { data: endpoint } = useProjectApiUrl({ projectRef })
const { can: canUpdateConfig } = useAsyncCheckPermissions(
PermissionAction.UPDATE,
'custom_config_gotrue'
)
const shouldDisableField = (field: string): boolean => {
const shouldDisableSmsFields =
config.HOOK_SEND_SMS_ENABLED &&
field.startsWith('SMS_') &&
![
'SMS_AUTOCONFIRM',
'SMS_OTP_EXP',
'SMS_OTP_LENGTH',
'SMS_OTP_LENGTH',
'SMS_TEMPLATE',
'SMS_TEST_OTP',
'SMS_TEST_OTP_VALID_UNTIL',
].includes(field)
return (
['EXTERNAL_SLACK_CLIENT_ID', 'EXTERNAL_SLACK_SECRET'].includes(field) ||
shouldDisableSmsFields
)
}
const hasEntitlementAccess = useHasEntitlementAccess()
const getValuesForProvider = useCallback(
(config: components['schemas']['GoTrueConfigResponse']) => {
const values: { [x: string]: string | boolean } = {}
Object.keys(provider.properties).forEach((key) => {
// This ensures the default value is visibly selected
if (key === 'PASSWORD_REQUIRED_CHARACTERS' && config.PASSWORD_REQUIRED_CHARACTERS === '') {
values[key] = NO_REQUIRED_CHARACTERS
return
}
const isDoubleNegative = doubleNegativeKeys.includes(key)
if (provider.title === 'SAML 2.0') {
const configValue = (config as any)[key]
values[key] = configValue || (provider.properties[key].type === 'boolean' ? false : '')
} else {
if (isDoubleNegative) {
values[key] = !(config as any)[key]
} else {
const configValue = (config as any)[key]
values[key] = configValue
? configValue
: provider.properties[key].type === 'boolean'
? false
: ''
}
}
})
return values
},
[provider]
)
const INITIAL_VALUES = useMemo(() => {
// This check will always be true but let us avoid adding an eslint disable comment on unused memo dependencies
// which could hide real issues in the future.
// Adding the provider in the memo dependencies ensures the INITIAL_VALUES is properly applied
if (!provider) return
return getValuesForProvider(config)
}, [config, getValuesForProvider, provider])
const onSubmit = (values: any) => {
const payload = { ...values }
Object.keys(values).map((x: string) => {
if (doubleNegativeKeys.includes(x)) payload[x] = !values[x]
if (payload[x] === '') payload[x] = null
})
// The backend uses empty string to represent no required characters in the password
if (payload.PASSWORD_REQUIRED_CHARACTERS === NO_REQUIRED_CHARACTERS) {
payload.PASSWORD_REQUIRED_CHARACTERS = ''
}
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
onSuccess: (newValues) => {
setOpen(false)
setUrlProvider(null)
form.reset(getValuesForProvider(newValues))
toast.success('Successfully updated settings')
},
}
)
}
// Handle clicking on a provider in the list
const handleProviderClick = () => setUrlProvider(provider.title)
const handleOpenChange = (isOpen: boolean) => {
// Remove provider query param from URL when closed
if (!isOpen) setUrlProvider(null)
}
// Open or close the form based on the query parameter
useEffect(() => {
const isProviderInQuery = urlProvider.toLowerCase() === provider.title.toLowerCase()
setOpen(isProviderInQuery)
}, [urlProvider, provider.title])
const form = useForm({
defaultValues: INITIAL_VALUES,
resolver: zodResolver(provider.validationSchema),
shouldUnregister: false,
})
useEffect(() => {
if (open) {
form.reset(INITIAL_VALUES)
}
}, [open, form, INITIAL_VALUES])
const formId = useId()
return (
<>
<ResourceItem
onClick={handleProviderClick}
media={
<img
src={`${BASE_PATH}/img/icons/${provider.misc.iconKey}${provider.misc.hasLightIcon && !resolvedTheme?.includes('dark') ? '-light' : ''}.svg`}
width={18}
height={18}
alt={`${provider.title} auth icon`}
/>
}
meta={
isActive ? (
<div className="flex items-center gap-1 rounded-full border border-brand-400 bg-brand-200 py-1 px-1 text-xs text-brand">
<span className="rounded-full bg-brand-default p-0.5 text-xs text-brand-200">
<Check strokeWidth={2} size={12} />
</span>
<span className="px-1">Enabled</span>
</div>
) : (
<div className="rounded-md border border-strong bg-surface-100 py-1 px-3 text-xs text-foreground-lighter">
Disabled
</div>
)
}
>
{provider.title}
</ResourceItem>
<Sheet open={open} onOpenChange={handleOpenChange}>
<SheetContent className="flex flex-col gap-0" size="lg">
<SheetHeader className="shrink-0 flex items-center gap-4">
<img
src={`${BASE_PATH}/img/icons/${provider.misc.iconKey}${provider.misc.hasLightIcon && !resolvedTheme?.includes('dark') ? '-light' : ''}.svg`}
width={18}
height={18}
alt={`${provider.title} auth icon`}
/>
<SheetTitle>{provider.title}</SheetTitle>
</SheetHeader>
<Form {...form}>
<form
id={formId}
name={formId}
className="overflow-y-auto grow px-0"
onSubmit={form.handleSubmit(onSubmit)}
>
<AuthAlert
title={provider.title}
isHookSendSMSEnabled={config.HOOK_SEND_SMS_ENABLED}
/>
{Object.keys(provider.properties).map((x: string) => {
const { entitlementKey } = provider.properties[x]
const hasAccess = entitlementKey == null || hasEntitlementAccess(entitlementKey)
return (
<FormField
key={x}
projectRef={projectRef}
organizationSlug={organization?.slug}
name={x}
properties={provider.properties[x]}
control={form.control}
readOnly={shouldDisableField(x) || !canUpdateConfig}
hasAccess={hasAccess}
/>
)
})}
{provider?.misc?.alert && (
<SheetSection>
<Admonition
type="warning"
title={provider.misc.alert.title}
description={<ReactMarkdown>{provider.misc.alert.description}</ReactMarkdown>}
/>
</SheetSection>
)}
{provider.misc.requiresRedirect && (
<SheetSection>
<FormItemLayout
layout="horizontal"
label="Callback URL (for OAuth)"
description={
<Markdown
content={provider.misc.helper}
className="text-foreground-lighter"
/>
}
>
<Input copy readOnly value={endpoint ? `${endpoint}/auth/v1/callback` : ''} />
</FormItemLayout>
</SheetSection>
)}
</form>
</Form>
<SheetFooter className="shrink-0">
<div className="flex items-center justify-between w-full">
<DocsButton href={provider.link} />
<div className="flex items-center gap-x-3">
<Button
type="reset"
onClick={() => {
setOpen(false)
setUrlProvider(null)
form.reset()
}}
disabled={isUpdatingConfig}
>
Cancel
</Button>
<ButtonTooltip
variant="primary"
form={formId}
type="submit"
loading={isUpdatingConfig}
disabled={isUpdatingConfig || !canUpdateConfig || !form.formState.isDirty}
tooltip={{
content: {
side: 'bottom',
text: !canUpdateConfig
? 'You need additional permissions to update provider settings'
: undefined,
},
}}
>
Save
</ButtonTooltip>
</div>
</div>
</SheetFooter>
</SheetContent>
</Sheet>
</>
)
}