mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Studio relies on repeated classes to style inline code. Bare `<code>` elements can miss those styles. ## Solution Import the shared styles from #51980 and remove the repeated classes. Keep Markdown renderer behaviour and existing size overrides. Use `data-code-style="plain"` for webhook headers, CLI and upgrade commands, configuration comparisons and connected-resource labels that have their own layout. ## Review instructions Dashboard review: this PR changes Studio only. 1. Open [Database > Extensions](https://studio-staging-git-dnywh-depr-707-code-studio-supabase.vercel.app/dashboard/project/_/database/extensions). Search for `pg_trgm` or another disabled extension and turn on its toggle to open the Enable dialog. Check the Extension and Schema values and the help text under “Install in a different schema”. The SQL block should keep its highlighting and copy control. Close without installing. 2. Open [Edge Functions > Secrets](https://studio-staging-git-dnywh-depr-707-code-studio-supabase.vercel.app/dashboard/project/_/functions/secrets). Scroll to “Default secrets” and check `SUPABASE_URL` and `SUPABASE_DB_URL`: both should use the bordered inline-code style. Hover a name to see “Click to copy”, then click it and confirm the name is copied. No custom secret or deployed function is needed. 3. Compare light and dark themes at narrow and desktop widths. | Before | After | | --- | --- | | <img width="812" height="1066" alt="CleanShot 2026-10-19 at 15 35 10@2x" src="https://github.com/user-attachments/assets/e4a21310-1fac-4143-9ee6-d2452ab4f314" /> | <img width="812" height="1068" alt="CleanShot 2026-10-20 at 15 39 20@2x" src="https://github.com/user-attachments/assets/d2c91ef6-7836-4c71-8f15-d0c0df8e969d" /> |
345 lines
13 KiB
TypeScript
345 lines
13 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useParams } from 'common'
|
|
import { ExternalLinkIcon } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { useEffect } from 'react'
|
|
import { useForm, useWatch } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Alert,
|
|
AlertDescription,
|
|
AlertTitle,
|
|
Button,
|
|
Card,
|
|
CardContent,
|
|
CardFooter,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Switch,
|
|
WarningIcon,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
import * as z from 'zod'
|
|
|
|
import { NO_REQUIRED_CHARACTERS } from './Auth.constants'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import { useAuthConfigQuery } from '@/data/auth/auth-config-query'
|
|
import { useAuthConfigUpdateMutation } from '@/data/auth/auth-config-update-mutation'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
|
|
const schema = z.object({
|
|
DISABLE_SIGNUP: z.boolean(),
|
|
EXTERNAL_ANONYMOUS_USERS_ENABLED: z.boolean(),
|
|
SECURITY_MANUAL_LINKING_ENABLED: z.boolean(),
|
|
MAILER_AUTOCONFIRM: z.boolean(),
|
|
SITE_URL: z.string().min(1, 'Must have a Site URL'),
|
|
})
|
|
|
|
export const BasicAuthSettingsForm = () => {
|
|
const { ref: projectRef } = useParams()
|
|
const showManualLinking = useIsFeatureEnabled('authentication:show_manual_linking')
|
|
|
|
const {
|
|
data: authConfig,
|
|
error: authConfigError,
|
|
isError,
|
|
isSuccess,
|
|
isPending: isLoading,
|
|
} = useAuthConfigQuery({ projectRef })
|
|
const { mutate: updateAuthConfig, isPending: isUpdatingConfig } = useAuthConfigUpdateMutation()
|
|
|
|
const { can: canReadConfig, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.AUTH_CONFIG_READ
|
|
)
|
|
const { can: canUpdateConfig } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.AUTH_CONFIG_WRITE
|
|
)
|
|
|
|
const form = useForm({
|
|
resolver: zodResolver(schema),
|
|
defaultValues: {
|
|
DISABLE_SIGNUP: true,
|
|
EXTERNAL_ANONYMOUS_USERS_ENABLED: false,
|
|
SECURITY_MANUAL_LINKING_ENABLED: false,
|
|
MAILER_AUTOCONFIRM: true,
|
|
SITE_URL: '',
|
|
},
|
|
})
|
|
const { isDirty } = form.formState
|
|
const externalAnonymousUsersEnabled = useWatch({
|
|
control: form.control,
|
|
name: 'EXTERNAL_ANONYMOUS_USERS_ENABLED',
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (authConfig) {
|
|
form.reset({
|
|
DISABLE_SIGNUP: !authConfig.DISABLE_SIGNUP,
|
|
EXTERNAL_ANONYMOUS_USERS_ENABLED: authConfig.EXTERNAL_ANONYMOUS_USERS_ENABLED,
|
|
SECURITY_MANUAL_LINKING_ENABLED: authConfig.SECURITY_MANUAL_LINKING_ENABLED,
|
|
// The backend uses false to represent that email confirmation is required
|
|
MAILER_AUTOCONFIRM: !authConfig.MAILER_AUTOCONFIRM,
|
|
SITE_URL: authConfig.SITE_URL,
|
|
})
|
|
}
|
|
}, [authConfig])
|
|
|
|
const onSubmit = (values: any) => {
|
|
const payload = { ...values }
|
|
payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUP
|
|
// 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 = ''
|
|
}
|
|
|
|
// The backend uses false to represent that email confirmation is required
|
|
payload.MAILER_AUTOCONFIRM = !values.MAILER_AUTOCONFIRM
|
|
|
|
updateAuthConfig(
|
|
{ projectRef: projectRef!, config: payload },
|
|
{
|
|
onError: (error) => {
|
|
toast.error(`Failed to update settings: ${error?.message}`)
|
|
},
|
|
onSuccess: () => {
|
|
toast.success('Successfully updated settings')
|
|
},
|
|
}
|
|
)
|
|
}
|
|
|
|
return (
|
|
<PageSection>
|
|
<PageSectionMeta>
|
|
<PageSectionSummary>
|
|
<PageSectionTitle>User Signups</PageSectionTitle>
|
|
</PageSectionSummary>
|
|
</PageSectionMeta>
|
|
<PageSectionContent>
|
|
{isError && (
|
|
<AlertError
|
|
error={authConfigError}
|
|
subject="Failed to retrieve auth configuration for hooks"
|
|
/>
|
|
)}
|
|
|
|
{isPermissionsLoaded && !canReadConfig && (
|
|
<div className="mt-8">
|
|
<NoPermission resourceText="view auth configuration settings" />
|
|
</div>
|
|
)}
|
|
|
|
{isLoading && (
|
|
<Card>
|
|
<CardContent className="py-6">
|
|
<ShimmeringLoader />
|
|
</CardContent>
|
|
<CardContent className="py-6">
|
|
<ShimmeringLoader />
|
|
</CardContent>
|
|
<CardContent className="py-6">
|
|
<ShimmeringLoader />
|
|
</CardContent>
|
|
<CardContent className="py-7">
|
|
<ShimmeringLoader />
|
|
</CardContent>
|
|
<CardContent className="py-7"></CardContent>
|
|
</Card>
|
|
)}
|
|
|
|
{isSuccess && (
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
|
<Card>
|
|
<CardContent>
|
|
<FormField
|
|
control={form.control}
|
|
name="DISABLE_SIGNUP"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Allow new users to sign up"
|
|
description="If this is disabled, new users will not be able to sign up to your application"
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={!canUpdateConfig}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</CardContent>
|
|
{showManualLinking && (
|
|
<CardContent>
|
|
<FormField
|
|
control={form.control}
|
|
name="SECURITY_MANUAL_LINKING_ENABLED"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Allow manual linking"
|
|
description={
|
|
<>
|
|
Enable{' '}
|
|
<InlineLink
|
|
className="text-foreground-light hover:text-foreground"
|
|
href={`${DOCS_URL}/guides/auth/auth-identity-linking#manual-linking-beta`}
|
|
>
|
|
manual linking APIs
|
|
</InlineLink>{' '}
|
|
for your project
|
|
</>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={!canUpdateConfig}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</CardContent>
|
|
)}
|
|
<CardContent>
|
|
<FormField
|
|
control={form.control}
|
|
name="EXTERNAL_ANONYMOUS_USERS_ENABLED"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Allow anonymous sign-ins"
|
|
description={
|
|
<>
|
|
Enable{' '}
|
|
<InlineLink
|
|
className="text-foreground-light hover:text-foreground"
|
|
href={`${DOCS_URL}/guides/auth/auth-anonymous`}
|
|
>
|
|
anonymous sign-ins
|
|
</InlineLink>{' '}
|
|
for your project
|
|
</>
|
|
}
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={!canUpdateConfig}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
{externalAnonymousUsersEnabled && (
|
|
<Alert
|
|
className="flex w-full items-center justify-between mt-4"
|
|
variant="warning"
|
|
>
|
|
<WarningIcon />
|
|
<div>
|
|
<AlertTitle>
|
|
Anonymous users will use the <code>authenticated</code> role when signing
|
|
in
|
|
</AlertTitle>
|
|
<AlertDescription className="flex flex-col gap-y-3">
|
|
<p>
|
|
As a result, anonymous users will be subjected to RLS policies that
|
|
apply to the <code>public</code> and <code>authenticated</code> roles.
|
|
We strongly advise{' '}
|
|
<Link
|
|
href={`/project/${projectRef}/database/policies`}
|
|
className="text-foreground underline"
|
|
>
|
|
reviewing your RLS policies
|
|
</Link>{' '}
|
|
to ensure that access to your data is restricted where required.
|
|
</p>
|
|
<Button asChild className="w-min" icon={<ExternalLinkIcon />}>
|
|
<Link href={`${DOCS_URL}/guides/auth/auth-anonymous#access-control`}>
|
|
View access control docs
|
|
</Link>
|
|
</Button>
|
|
</AlertDescription>
|
|
</div>
|
|
</Alert>
|
|
)}
|
|
|
|
{!authConfig?.SECURITY_CAPTCHA_ENABLED && externalAnonymousUsersEnabled && (
|
|
<Alert className="mt-4">
|
|
<WarningIcon />
|
|
<AlertTitle>
|
|
We highly recommend{' '}
|
|
<InlineLink href={`/project/${projectRef}/auth/protection`}>
|
|
enabling captcha
|
|
</InlineLink>{' '}
|
|
for anonymous sign-ins
|
|
</AlertTitle>
|
|
<AlertDescription>
|
|
This will prevent potential abuse on sign-ins which may bloat your database
|
|
and incur costs for monthly active users (MAU)
|
|
</AlertDescription>
|
|
</Alert>
|
|
)}
|
|
</CardContent>
|
|
<CardContent>
|
|
<FormField
|
|
control={form.control}
|
|
name="MAILER_AUTOCONFIRM"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Confirm email"
|
|
description="Users will need to confirm their email address before signing in for the first time"
|
|
>
|
|
<FormControl>
|
|
<Switch
|
|
checked={field.value}
|
|
onCheckedChange={field.onChange}
|
|
disabled={!canUpdateConfig}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
</CardContent>
|
|
<CardFooter className="justify-end space-x-2">
|
|
{isDirty && <Button onClick={() => form.reset()}>Cancel</Button>}
|
|
<Button
|
|
variant="primary"
|
|
type="submit"
|
|
disabled={!canUpdateConfig || isUpdatingConfig || !isDirty}
|
|
loading={isUpdatingConfig}
|
|
>
|
|
Save changes
|
|
</Button>
|
|
</CardFooter>
|
|
</Card>
|
|
</form>
|
|
</Form>
|
|
)}
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
)
|
|
}
|