The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(studio): split auth templates into subpages (#39831)
Danny White0c65581e6cb3
diff --git a/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx b/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsxindex 390ba87c0e7..bf09377ebed 100644--- a/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx+++ b/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx@@ -9,7 +9,8 @@ const CONFIRMATION: FormSchema = {$schema: JSON_SCHEMA_VERSION,id: 'CONFIRMATION',type: 'object',- title: 'Confirm signup',+ title: 'Confirm sign up',+ purpose: 'Email verification for new user registrations',properties: {MAILER_SUBJECTS_CONFIRMATION: {title: 'Subject heading',@@ -20,7 +21,7 @@ const CONFIRMATION: FormSchema = {descriptionOptional: 'HTML body of your email',type: 'code',description: `-- \`{{ .ConfirmationURL }}\` : URL to confirm the e-mail address for the new account+- \`{{ .ConfirmationURL }}\` : URL to confirm the email address for the new account- \`{{ .Token }}\` : The 6-digit numeric email OTP- \`{{ .TokenHash }}\` : The hashed token used in the URL- \`{{ .SiteURL }}\` : The URL of the site@@ -45,6 +46,7 @@ const INVITE: FormSchema = {id: 'INVITE',type: 'object',title: 'Invite user',+ purpose: "Allows administrators to invite users who don't have accounts yet",properties: {MAILER_SUBJECTS_INVITE: {title: 'Subject heading',@@ -79,7 +81,8 @@ const MAGIC_LINK: FormSchema = {$schema: JSON_SCHEMA_VERSION,id: 'MAGIC_LINK',type: 'object',- title: 'Magic Link',+ title: 'Magic link',+ purpose: 'Passwordless login using email links',properties: {MAILER_SUBJECTS_MAGIC_LINK: {title: 'Subject heading',@@ -114,7 +117,8 @@ const EMAIL_CHANGE: FormSchema = {$schema: JSON_SCHEMA_VERSION,id: 'EMAIL_CHANGE',type: 'object',- title: 'Change Email Address',+ title: 'Change email address',+ purpose: 'Verification for email address changes',properties: {MAILER_SUBJECTS_EMAIL_CHANGE: {title: 'Subject heading',@@ -150,7 +154,8 @@ const RECOVERY: FormSchema = {$schema: JSON_SCHEMA_VERSION,id: 'RECOVERY',type: 'object',- title: 'Reset Password',+ title: 'Reset password',+ purpose: 'Password recovery flow for users who forgot their password',properties: {MAILER_SUBJECTS_RECOVERY: {title: 'Subject heading',@@ -185,6 +190,8 @@ const REAUTHENTICATION: FormSchema = {id: 'REAUTHENTICATION',type: 'object',title: 'Reauthentication',+ purpose:+ 'Additional verification for sensitive actions (like changing password, deleting account)',properties: {MAILER_SUBJECTS_REAUTHENTICATION: {title: 'Subject heading',diff --git a/apps/studio/components/interfaces/Auth/EmailRateLimitsAlert/EmailRateLimitsAlert.tsx b/apps/studio/components/interfaces/Auth/EmailRateLimitsAlert/EmailRateLimitsAlert.tsxindex 86c6a517ba1..09ea5b0e908 100644--- a/apps/studio/components/interfaces/Auth/EmailRateLimitsAlert/EmailRateLimitsAlert.tsx+++ b/apps/studio/components/interfaces/Auth/EmailRateLimitsAlert/EmailRateLimitsAlert.tsx@@ -3,34 +3,28 @@ import Link from 'next/link'import { useParams } from 'common'import { InlineLink } from 'components/ui/InlineLink'import { DOCS_URL } from 'lib/constants'-import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Button,- WarningIcon,-} from 'ui'+import { Button } from 'ui'+import { Admonition } from 'ui-patterns/admonition'export function EmailRateLimitsAlert() {const { ref } = useParams()return (- <Alert_Shadcn_ variant="warning">- <WarningIcon />- <AlertTitle_Shadcn_>Email rate-limits and restrictions</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- You're using the built-in email service. The service has rate limits and it's not meant to- be used for production apps. Check the{' '}+ <Admonition+ type="warning"+ title="Set up custom SMTP"+ className="bg-warning-200 border-warning-400"+ >+ <p>+ You’re using the built-in email service. This service has rate limits and is not meant to be+ used for production apps.{' '}<InlineLink href={`${DOCS_URL}/guides/platform/going-into-prod#auth-rate-limits`}>- documentation+ Learn more</InlineLink>{' '}- for an up-to-date information on the current rate limits.- </AlertDescription_Shadcn_>- <AlertDescription_Shadcn_ className="mt-2">- <Button asChild type="default">- <Link href={`/project/${ref}/auth/smtp`}>Set up custom SMTP server</Link>- </Button>- </AlertDescription_Shadcn_>- </Alert_Shadcn_>+ </p>+ <Button asChild type="default" className="mt-2">+ <Link href={`/project/${ref}/auth/smtp`}>Set up SMTP</Link>+ </Button>+ </Admonition>)}diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsxindex 71b8164e694..1f5c9921a48 100644--- a/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx+++ b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx@@ -1,13 +1,26 @@import { useParams } from 'common'+import { useIsSecurityNotificationsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'+import { ScaffoldSection } from 'components/layouts/Scaffold'import AlertError from 'components/ui/AlertError'import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'import { useAuthConfigQuery } from 'data/auth/auth-config-query'-import { Card, Tabs_Shadcn_, TabsContent_Shadcn_, TabsList_Shadcn_, TabsTrigger_Shadcn_ } from 'ui'+import { ChevronRight } from 'lucide-react'+import Link from 'next/link'+import {+ Card,+ CardContent,+ Tabs_Shadcn_,+ TabsContent_Shadcn_,+ TabsList_Shadcn_,+ TabsTrigger_Shadcn_,+} from 'ui'import { TEMPLATES_SCHEMAS } from '../AuthTemplatesValidation'import EmailRateLimitsAlert from '../EmailRateLimitsAlert'+import { slugifyTitle } from './EmailTemplates.utils'import TemplateEditor from './TemplateEditor'export const EmailTemplates = () => {+ const isSecurityNotificationsEnabled = useIsSecurityNotificationsEnabled()const { ref: projectRef } = useParams()const {data: authConfig,@@ -23,7 +36,7 @@ export const EmailTemplates = () => {(!authConfig.SMTP_HOST || !authConfig.SMTP_USER || !authConfig.SMTP_PASS)return (- <div className="w-full">+ <ScaffoldSection isFullWidth className="!pt-0">{isError && (<AlertErrorclassName="mt-12"@@ -43,32 +56,59 @@ export const EmailTemplates = () => {<EmailRateLimitsAlert /></div>) : null}- <Card>- <Tabs_Shadcn_ defaultValue={TEMPLATES_SCHEMAS[0].title.trim().replace(/\s+/g, '-')}>- <TabsList_Shadcn_ className="pt-2 px-6 gap-5 mb-0 overflow-x-scroll no-scrollbar mb-4">- {TEMPLATES_SCHEMAS.map((template) => {- return (- <TabsTrigger_Shadcn_- key={`${template.id}`}- value={template.title.trim().replace(/\s+/g, '-')}- >- {template.title}- </TabsTrigger_Shadcn_>- )- })}- </TabsList_Shadcn_>+ {isSecurityNotificationsEnabled ? (+ <Card>{TEMPLATES_SCHEMAS.map((template) => {- const panelId = template.title.trim().replace(/\s+/g, '-')+ const templateSlug = slugifyTitle(template.title)return (- <TabsContent_Shadcn_ key={panelId} value={panelId} className="mt-0">- <TemplateEditor key={template.title} template={template} />- </TabsContent_Shadcn_>+ <CardContent key={`${template.id}`} className="p-0">+ <Link+ href={`/project/${projectRef}/auth/templates/${templateSlug}`}+ className="flex items-center justify-between hover:bg-surface-200 transition-colors py-4 px-6 w-full h-full"+ >+ <div className="flex flex-col">+ <h3 className="text-sm text-foreground">{template.title}</h3>+ {template.purpose && (+ <p className="text-sm text-foreground-lighter">{template.purpose}</p>+ )}+ </div>+ <ChevronRight+ size={16}+ className="text-foreground-muted group-hover:text-foreground transition-colors"+ />+ </Link>+ </CardContent>)})}- </Tabs_Shadcn_>- </Card>+ </Card>+ ) : (+ <Card>+ <Tabs_Shadcn_ defaultValue={slugifyTitle(TEMPLATES_SCHEMAS[0].title)}>+ <TabsList_Shadcn_ className="pt-2 px-6 gap-5 mb-0 overflow-x-scroll no-scrollbar mb-4">+ {TEMPLATES_SCHEMAS.map((template) => {+ return (+ <TabsTrigger_Shadcn_+ key={`${template.id}`}+ value={slugifyTitle(template.title)}+ >+ {template.title}+ </TabsTrigger_Shadcn_>+ )+ })}+ </TabsList_Shadcn_>+ {TEMPLATES_SCHEMAS.map((template) => {+ const panelId = slugifyTitle(template.title)+ return (+ <TabsContent_Shadcn_ key={panelId} value={panelId} className="mt-0">+ <TemplateEditor key={template.title} template={template} />+ </TabsContent_Shadcn_>+ )+ })}+ </Tabs_Shadcn_>+ </Card>+ )}</div>)}- </div>+ </ScaffoldSection>)}diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.tsnew file mode 100644index 00000000000..e1297392939--- /dev/null+++ b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts@@ -0,0 +1,8 @@+/**+ * Convert template title to URL-friendly slug+ * Shared function to ensure slug matching works correctly across multiple files+ * Necessary because TEMPLATES_SCHEMAS does not provide a slug for each template+ */+export const slugifyTitle = (title: string) => {+ return title.trim().replace(/\s+/g, '-').toLowerCase()+}diff --git a/apps/studio/components/layouts/AuthLayout/AuthEmailsLayout.tsx b/apps/studio/components/layouts/AuthLayout/AuthEmailsLayout.tsxindex fe69585fe33..1d2754ffc5c 100644--- a/apps/studio/components/layouts/AuthLayout/AuthEmailsLayout.tsx+++ b/apps/studio/components/layouts/AuthLayout/AuthEmailsLayout.tsx@@ -8,6 +8,7 @@ import AuthLayout from './AuthLayout'export const AuthEmailsLayout = ({ children }: PropsWithChildren<{}>) => {const { ref } = useParams()+const showEmails = useIsFeatureEnabled('authentication:emails')const navItems = [diff --git a/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx b/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsxnew file mode 100644index 00000000000..f3097485c6b--- /dev/null+++ b/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx@@ -0,0 +1,117 @@+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { useIsSecurityNotificationsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'+import { TEMPLATES_SCHEMAS } from 'components/interfaces/Auth/AuthTemplatesValidation'+import { slugifyTitle } from 'components/interfaces/Auth/EmailTemplates/EmailTemplates.utils'+import TemplateEditor from 'components/interfaces/Auth/EmailTemplates/TemplateEditor'+import AuthLayout from 'components/layouts/AuthLayout/AuthLayout'+import DefaultLayout from 'components/layouts/DefaultLayout'+import { PageLayout } from 'components/layouts/PageLayout/PageLayout'+import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'+import { DocsButton } from 'components/ui/DocsButton'+import NoPermission from 'components/ui/NoPermission'+import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'+import { DOCS_URL } from 'lib/constants'+import Link from 'next/link'+import { useRouter } from 'next/router'+import { useEffect } from 'react'+import type { NextPageWithLayout } from 'types'+import { Button, Card } from 'ui'+import { Admonition, GenericSkeletonLoader } from 'ui-patterns'++const TemplatePage: NextPageWithLayout = () => {+ return <RedirectToTemplates />+}++const RedirectToTemplates = () => {+ const router = useRouter()+ const { templateId, ref } = router.query+ const isSecurityNotificationsEnabled = useIsSecurityNotificationsEnabled()++ const { can: canReadAuthSettings, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissions(+ PermissionAction.READ,+ 'custom_config_gotrue'+ )++ useEffect(() => {+ if (isPermissionsLoaded && !isSecurityNotificationsEnabled) {+ router.replace(`/project/${ref}/auth/templates/`)+ }+ }, [isPermissionsLoaded, isSecurityNotificationsEnabled, ref, router])++ if (isPermissionsLoaded && !canReadAuthSettings) {+ return <NoPermission isFullPage resourceText="access your project's email settings" />+ }++ if (!isSecurityNotificationsEnabled) {+ return null+ }++ // Find template whose slug matches the URL slug+ const template =+ templateId && typeof templateId === 'string'+ ? TEMPLATES_SCHEMAS.find((template) => slugifyTitle(template.title) === templateId)+ : null++ // Show error if templateId is invalid or template is not found+ if (!template || !templateId || typeof templateId !== 'string') {+ return (+ <div className="flex h-full w-full items-center justify-center">+ <Admonition+ className="max-w-md"+ type="default"+ title="Unable to find template"+ description={`${templateId ? `The template "${templateId}"` : 'This template'} doesn’t seem to exist.`}+ >+ <Button asChild type="default" className="mt-2">+ <Link href={`/project/${ref}/auth/templates`}>Head back</Link>+ </Button>+ </Admonition>+ </div>+ )+ }++ // Convert templateId slug to one lowercase word to match docs anchor tag+ const templateIdForDocs = templateId.replace(/-/g, '').toLowerCase()++ return (+ <PageLayout+ title={template.title}+ subtitle={template.purpose || 'Configure and customize email templates.'}+ breadcrumbs={[+ {+ label: 'Emails',+ href: `/project/${ref}/auth/templates`,+ },+ ]}+ secondaryActions={[+ <DocsButton+ key="docs"+ href={`${DOCS_URL}/guides/local-development/customizing-email-templates#authemailtemplate${templateIdForDocs}`}+ />,+ ]}+ >+ <ScaffoldContainer bottomPadding>+ {!isPermissionsLoaded ? (+ <ScaffoldSection isFullWidth>+ <GenericSkeletonLoader />+ </ScaffoldSection>+ ) : (+ <ScaffoldSection isFullWidth>+ <Card>+ <TemplateEditor template={template} />+ </Card>+ </ScaffoldSection>+ )}+ </ScaffoldContainer>+ </PageLayout>+ )+}++TemplatePage.getLayout = (page) => (+ <DefaultLayout>+ <AuthLayout>{page}</AuthLayout>+ </DefaultLayout>+)++export default TemplatePagediff --git a/apps/studio/pages/project/[ref]/auth/templates.tsx b/apps/studio/pages/project/[ref]/auth/templates/index.tsxsimilarity index 97%rename from apps/studio/pages/project/[ref]/auth/templates.tsxrename to apps/studio/pages/project/[ref]/auth/templates/index.tsxindex cc1ccbaa0fe..dbd048e4938 100644--- a/apps/studio/pages/project/[ref]/auth/templates.tsx+++ b/apps/studio/pages/project/[ref]/auth/templates/index.tsx@@ -20,7 +20,7 @@ const TemplatesPage: NextPageWithLayout = () => {}return (- <ScaffoldContainer>+ <ScaffoldContainer bottomPadding>{!isPermissionsLoaded ? (<ScaffoldSection isFullWidth><GenericSkeletonLoader />diff --git a/apps/studio/types/form.ts b/apps/studio/types/form.tsindex 061b8a7105c..8a4bf1380d6 100644--- a/apps/studio/types/form.ts+++ b/apps/studio/types/form.ts@@ -9,6 +9,7 @@ export interface FormSchema {id?: stringtype: 'object'title: string+ purpose?: stringproperties: {[x: string]: {title: string