Skip to content

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

feat(auth): add account changes notifications template schemas (#39899)

issuedatfaf8107d69c7
diff --git a/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx b/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx
index bf09377ebed..7d35614d2e9 100644
--- a/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx
+++ b/apps/studio/components/interfaces/Auth/AuthTemplatesValidation.tsx
@@ -1,6 +1,4 @@
import { object, string } from 'yup'
-
-import { DOCS_URL } from 'lib/constants'
import type { FormSchema } from 'types'
const JSON_SCHEMA_VERSION = 'http://json-schema.org/draft-07/schema#'
@@ -32,12 +30,10 @@ const CONFIRMATION: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_CONFIRMATION: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_CONFIRMATION: string().required('Subject heading is required.'),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'authentication',
},
}
@@ -68,12 +64,10 @@ const INVITE: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_INVITE: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_INVITE: string().required('Subject heading is required.'),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'authentication',
},
}
@@ -104,12 +98,10 @@ const MAGIC_LINK: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_MAGIC_LINK: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_MAGIC_LINK: string().required('Subject heading is required.'),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'authentication',
},
}
@@ -141,12 +133,10 @@ const EMAIL_CHANGE: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_EMAIL_CHANGE: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_EMAIL_CHANGE: string().required('Subject heading is required.'),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'authentication',
},
}
@@ -177,12 +167,10 @@ const RECOVERY: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_RECOVERY: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_RECOVERY: string().required('Subject heading is required.'),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'authentication',
},
}
const REAUTHENTICATION: FormSchema = {
@@ -210,12 +198,229 @@ const REAUTHENTICATION: FormSchema = {
},
},
validationSchema: object().shape({
- MAILER_SUBJECTS_REAUTHENTICATION: string().required('"Subject heading is required.'),
+ MAILER_SUBJECTS_REAUTHENTICATION: string().required('Subject heading is required.'),
+ }),
+ misc: {
+ emailTemplateType: 'authentication',
+ },
+}
+
+// Notifications
+const PASSWORD_CHANGED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'PASSWORD_CHANGED_NOTIFICATION',
+ type: 'object',
+ title: 'Password changed notification',
+ purpose: 'Notify a user when their password has been changed',
+ properties: {
+ MAILER_SUBJECTS_PASSWORD_CHANGED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_PASSWORD_CHANGED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_PASSWORD_CHANGED_NOTIFICATION: string().required(
+ 'Subject heading is required.'
+ ),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const EMAIL_CHANGED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'EMAIL_CHANGED_NOTIFICATION',
+ type: 'object',
+ title: 'Email changed notification',
+ purpose: 'Notify a user when their email address has been changed',
+ properties: {
+ MAILER_SUBJECTS_EMAIL_CHANGED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_EMAIL_CHANGED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's new email address
+- \`{{ .OldEmail }}\` : The user's old email address
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_EMAIL_CHANGED_NOTIFICATION: string().required('Subject heading is required.'),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const PHONE_CHANGED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'PHONE_CHANGED_NOTIFICATION',
+ type: 'object',
+ title: 'Phone changed notification',
+ purpose: 'Notify a user when the phone number has been changed',
+ properties: {
+ MAILER_SUBJECTS_PHONE_CHANGED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_PHONE_CHANGED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .Phone }}\` : The user's new phone number
+- \`{{ .OldPhone }}\` : The user's old phone number
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_PHONE_CHANGED_NOTIFICATION: string().required('Subject heading is required.'),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const IDENTITY_LINKED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'IDENTITY_LINKED_NOTIFICATION',
+ type: 'object',
+ title: 'Identity linked notification',
+ purpose: 'Notify a user when a new identity has been linked to their account',
+ properties: {
+ MAILER_SUBJECTS_IDENTITY_LINKED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_IDENTITY_LINKED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .Provider }}\` : The provider of the newly linked identity
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_IDENTITY_LINKED_NOTIFICATION: string().required('Subject heading is required.'),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const IDENTITY_UNLINKED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'IDENTITY_UNLINKED_NOTIFICATION',
+ type: 'object',
+ title: 'Identity unlinked notification',
+ purpose: 'Notify a user when an identity has been unlinked from their account',
+ properties: {
+ MAILER_SUBJECTS_IDENTITY_UNLINKED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_IDENTITY_UNLINKED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .Provider }}\` : The provider of the unlinked identity
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_IDENTITY_UNLINKED_NOTIFICATION: string().required(
+ 'Subject heading is required.'
+ ),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const MFA_FACTOR_ENROLLED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'MFA_FACTOR_ENROLLED_NOTIFICATION',
+ type: 'object',
+ title: 'MFA factor enrolled notification',
+ purpose: 'Notify a user when a new MFA factor has been enrolled for their account',
+ properties: {
+ MAILER_SUBJECTS_MFA_FACTOR_ENROLLED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_MFA_FACTOR_ENROLLED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .FactorType }}\` : The type of the newly enrolled MFA factor
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_MFA_FACTOR_ENROLLED_NOTIFICATION: string().required(
+ 'Subject heading is required.'
+ ),
+ }),
+ misc: {
+ emailTemplateType: 'security',
+ },
+}
+
+const MFA_FACTOR_UNENROLLED_NOTIFICATION: FormSchema = {
+ $schema: JSON_SCHEMA_VERSION,
+ id: 'MFA_FACTOR_UNENROLLED_NOTIFICATION',
+ type: 'object',
+ title: 'MFA factor unenrolled notification',
+ purpose: 'Notify a user when an MFA factor has been unenrolled from their account',
+ properties: {
+ MAILER_SUBJECTS_MFA_FACTOR_UNENROLLED_NOTIFICATION: {
+ title: 'Subject heading',
+ type: 'string',
+ },
+ MAILER_TEMPLATES_MFA_FACTOR_UNENROLLED_NOTIFICATION_CONTENT: {
+ title: 'Message body',
+ descriptionOptional: 'HTML body of your email',
+ type: 'code',
+ description: `
+- \`{{ .Email }}\` : The user's email address
+- \`{{ .FactorType }}\` : The type of the newly enrolled MFA factor
+- \`{{ .Data }}\` : The user's \`user_metadata\`
+`,
+ },
+ },
+ validationSchema: object().shape({
+ MAILER_SUBJECTS_MFA_FACTOR_UNENROLLED_NOTIFICATION: string().required(
+ 'Subject heading is required.'
+ ),
}),
misc: {
- iconKey: 'email-icon2',
- helper: `To complete setup, add this authorisation callback URL to your app's configuration in the Apple Developer Console.
-[Learn more](${DOCS_URL}/guides/auth/social-login/auth-apple#configure-your-services-id)`,
+ emailTemplateType: 'security',
},
}
@@ -226,4 +431,12 @@ export const TEMPLATES_SCHEMAS = [
EMAIL_CHANGE,
RECOVERY,
REAUTHENTICATION,
+ // Notifications
+ PASSWORD_CHANGED_NOTIFICATION,
+ EMAIL_CHANGED_NOTIFICATION,
+ PHONE_CHANGED_NOTIFICATION,
+ IDENTITY_LINKED_NOTIFICATION,
+ IDENTITY_UNLINKED_NOTIFICATION,
+ MFA_FACTOR_ENROLLED_NOTIFICATION,
+ MFA_FACTOR_UNENROLLED_NOTIFICATION,
]
diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
index 1f5c9921a48..26ddf458cbb 100644
--- a/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
+++ b/apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
@@ -1,14 +1,29 @@
+import { zodResolver } from '@hookform/resolvers/zod'
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { ChevronRight } from 'lucide-react'
+import Link from 'next/link'
+import { useEffect } from 'react'
+import { useForm } from 'react-hook-form'
+import { toast } from 'sonner'
+import { z } from 'zod'
+
import { useParams } from 'common'
import { useIsSecurityNotificationsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
-import { ScaffoldSection } from 'components/layouts/Scaffold'
+import { ScaffoldSection, ScaffoldSectionTitle } 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 { ChevronRight } from 'lucide-react'
-import Link from 'next/link'
+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'
+import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import {
+ Button,
Card,
CardContent,
+ CardFooter,
+ Form_Shadcn_,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Switch,
Tabs_Shadcn_,
TabsContent_Shadcn_,
TabsList_Shadcn_,
@@ -17,11 +32,32 @@ import {
import { TEMPLATES_SCHEMAS } from '../AuthTemplatesValidation'
import EmailRateLimitsAlert from '../EmailRateLimitsAlert'
import { slugifyTitle } from './EmailTemplates.utils'
-import TemplateEditor from './TemplateEditor'
+import { TemplateEditor } from './TemplateEditor'
+
+const notificationEnabledKeys = TEMPLATES_SCHEMAS.filter(
+ (t) => t.misc?.emailTemplateType === 'security'
+).map((template) => {
+ return `MAILER_NOTIFICATIONS_${template.id?.replace('_NOTIFICATION', '')}_ENABLED`
+})
+
+const NotificationsFormSchema = z.object({
+ ...notificationEnabledKeys.reduce(
+ (acc, key) => {
+ acc[key] = z.boolean()
+ return acc
+ },
+ {} as Record<string, z.ZodBoolean>
+ ),
+})
export const EmailTemplates = () => {
- const isSecurityNotificationsEnabled = useIsSecurityNotificationsEnabled()
const { ref: projectRef } = useParams()
+ const isSecurityNotificationsEnabled = useIsSecurityNotificationsEnabled()
+ const { can: canUpdateConfig } = useAsyncCheckPermissions(
+ PermissionAction.UPDATE,
+ 'custom_config_gotrue'
+ )
+
const {
data: authConfig,
error: authConfigError,
@@ -30,11 +66,45 @@ export const EmailTemplates = () => {
isSuccess,
} = useAuthConfigQuery({ projectRef })
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation({
+ onError: (error) => {
+ toast.error(`Failed to update settings: ${error?.message}`)
+ },
+ onSuccess: () => {
+ toast.success('Successfully updated settings')
+ },
+ })
+
const builtInSMTP =
isSuccess &&
authConfig &&
(!authConfig.SMTP_HOST || !authConfig.SMTP_USER || !authConfig.SMTP_PASS)
+ const defaultValues = notificationEnabledKeys.reduce(
+ (acc, key) => {
+ acc[key] = authConfig ? Boolean(authConfig[key as keyof typeof authConfig]) : false
+ return acc
+ },
+ {} as Record<string, boolean>
+ )
+
+ const notificationsForm = useForm<z.infer<typeof NotificationsFormSchema>>({
+ resolver: zodResolver(NotificationsFormSchema),
+ defaultValues,
+ })
+
+ const onSubmit = (values: any) => {
+ if (!projectRef) return console.error('Project ref is required')
+ updateAuthConfig({ projectRef: projectRef, config: { ...values } })
+ }
+
+ useEffect(() => {
+ if (authConfig) {
+ notificationsForm.reset(defaultValues)
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [authConfig])
+
return (
<ScaffoldSection isFullWidth className="!pt-0">
{isError && (
@@ -52,51 +122,145 @@ export const EmailTemplates = () => {
{isSuccess && (
<div className="my-12">
{builtInSMTP ? (
- <div className="mb-4">
+ <div className="mb-12">
<EmailRateLimitsAlert />
</div>
) : null}
{isSecurityNotificationsEnabled ? (
- <Card>
- {TEMPLATES_SCHEMAS.map((template) => {
- const templateSlug = slugifyTitle(template.title)
- return (
- <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 className="space-y-12">
+ <div>
+ <ScaffoldSectionTitle className="mb-4">Authentication</ScaffoldSectionTitle>
+ <Card>
+ {TEMPLATES_SCHEMAS.filter(
+ (t) => t.misc?.emailTemplateType === 'authentication'
+ ).map((template) => {
+ const templateSlug = slugifyTitle(template.title)
+
+ return (
+ <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>
+
+ <div className="flex items-center gap-4 group">
+ <ChevronRight
+ size={16}
+ className="text-foreground-muted group-hover:text-foreground transition-colors"
+ />
+ </div>
+ </Link>
+ </CardContent>
+ )
+ })}
+ </Card>
+ </div>
+
+ <div>
+ <ScaffoldSectionTitle className="mb-4">Security</ScaffoldSectionTitle>
+ <Form_Shadcn_ {...notificationsForm}>
+ <form onSubmit={notificationsForm.handleSubmit(onSubmit)} className="space-y-4">
+ <Card>
+ {TEMPLATES_SCHEMAS.filter(
+ (t) => t.misc?.emailTemplateType === 'security'
+ ).map((template) => {
+ const templateSlug = slugifyTitle(template.title)
+ const templateEnabledKey =
+ `MAILER_NOTIFICATIONS_${template.id?.replace('_NOTIFICATION', '')}_ENABLED` as keyof typeof authConfig
+
+ return (
+ <CardContent
+ key={`${template.id}`}
+ className="p-0 flex items-center justify-between hover:bg-surface-200 transition-colors w-full h-full"
+ >
+ <Link
+ href={`/project/${projectRef}/auth/templates/${templateSlug}`}
+ className="flex flex-col flex-1 py-4 px-6"
+ >
+ <h3 className="text-sm text-foreground">{template.title}</h3>
+ {template.purpose && (
+ <p className="text-sm text-foreground-lighter">
+ {template.purpose}
+ </p>
+ )}
+ </Link>
+
+ <div className="flex items-center gap-4 group h-full pl-2">
+ <FormField_Shadcn_
+ control={notificationsForm.control}
+ name={templateEnabledKey}
+ render={({ field }) => (
+ <FormControl_Shadcn_>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={!canUpdateConfig}
+ />
+ </FormControl_Shadcn_>
+ )}
+ />
+
+ <Link
+ href={`/project/${projectRef}/auth/templates/${templateSlug}`}
+ className="py-6 pr-6"
+ >
+ <ChevronRight
+ size={16}
+ className="text-foreground-muted hover:text-foreground transition-colors"
+ />
+ </Link>
+ </div>
+ </CardContent>
+ )
+ })}
+ <CardFooter className="justify-end space-x-2">
+ {notificationsForm.formState.isDirty && (
+ <Button type="default" onClick={() => notificationsForm.reset()}>
+ Cancel
+ </Button>
)}
- </div>
- <ChevronRight
- size={16}
- className="text-foreground-muted group-hover:text-foreground transition-colors"
- />
- </Link>
- </CardContent>
- )
- })}
- </Card>
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={
+ !canUpdateConfig ||
+ isUpdatingConfig ||
+ !notificationsForm.formState.isDirty
+ }
+ loading={isUpdatingConfig}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ </div>
+ </div>
) : (
<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_>
- )
- })}
+ {TEMPLATES_SCHEMAS.filter(
+ (t) => t.misc?.emailTemplateType === 'authentication'
+ ).map((template) => (
+ <TabsTrigger_Shadcn_
+ key={`${template.id}`}
+ value={slugifyTitle(template.title)}
+ >
+ {template.title}
+ </TabsTrigger_Shadcn_>
+ ))}
</TabsList_Shadcn_>
- {TEMPLATES_SCHEMAS.map((template) => {
+ {TEMPLATES_SCHEMAS.filter(
+ (t) => t.misc?.emailTemplateType === 'authentication'
+ ).map((template) => {
const panelId = slugifyTitle(template.title)
return (
<TabsContent_Shadcn_ key={panelId} value={panelId} className="mt-0">
diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/SpamValidation.tsx b/apps/studio/components/interfaces/Auth/EmailTemplates/SpamValidation.tsx
index 06d3619bc9f..89d69e61ed8 100644
--- a/apps/studio/components/interfaces/Auth/EmailTemplates/SpamValidation.tsx
+++ b/apps/studio/components/interfaces/Auth/EmailTemplates/SpamValidation.tsx
@@ -1,6 +1,7 @@
+import { Check, MailWarning } from 'lucide-react'
+
import { Markdown } from 'components/interfaces/Markdown'
import { ValidateSpamResponse } from 'data/auth/validate-spam-mutation'
-import { Check, MailWarning } from 'lucide-react'
import { Separator, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'
interface SpamValidationProps {
diff --git a/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
index e70e547934b..47334435239 100644
--- a/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
+++ b/apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
@@ -38,7 +38,7 @@ interface TemplateEditorProps {
template: FormSchema
}
-const TemplateEditor = ({ template }: TemplateEditorProps) => {
+export const TemplateEditor = ({ template }: TemplateEditorProps) => {
const { ref: projectRef } = useParams()
const { can: canUpdateConfig } = useAsyncCheckPermissions(
PermissionAction.UPDATE,
@@ -383,5 +383,3 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
</Form_Shadcn_>
)
}
-
-export default TemplateEditor
diff --git a/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx b/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
index f3097485c6b..30951b5af5b 100644
--- a/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
+++ b/apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
@@ -1,9 +1,12 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
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 { 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'
@@ -12,9 +15,6 @@ 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'
@@ -33,6 +33,16 @@ const RedirectToTemplates = () => {
'custom_config_gotrue'
)
+ // Find template whose slug matches the URL slug
+ const template =
+ templateId && typeof templateId === 'string'
+ ? TEMPLATES_SCHEMAS.find((template) => slugifyTitle(template.title) === templateId)
+ : null
+
+ // Convert templateId slug to one lowercase word to match docs anchor tag
+ const templateIdForDocs =
+ typeof templateId === 'string' ? templateId.replace(/-/g, '').toLowerCase() : ''
+
useEffect(() => {
if (isPermissionsLoaded && !isSecurityNotificationsEnabled) {
router.replace(`/project/${ref}/auth/templates/`)
@@ -43,18 +53,12 @@ const RedirectToTemplates = () => {
return <NoPermission isFullPage resourceText="access your project's email settings" />
}
- if (!isSecurityNotificationsEnabled) {
+ if (!isSecurityNotificationsEnabled || !templateId) {
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') {
+ if (!template) {
return (
<div className="flex h-full w-full items-center justify-center">
<Admonition
@@ -71,9 +75,6 @@ const RedirectToTemplates = () => {
)
}
- // Convert templateId slug to one lowercase word to match docs anchor tag
- const templateIdForDocs = templateId.replace(/-/g, '').toLowerCase()
-
return (
<PageLayout
title={template.title}
diff --git a/apps/studio/types/form.ts b/apps/studio/types/form.ts
index 8a4bf1380d6..0bd0bce02a1 100644
--- a/apps/studio/types/form.ts
+++ b/apps/studio/types/form.ts
@@ -32,5 +32,6 @@ export interface FormSchema {
title?: string
description?: string
}
+ emailTemplateType?: 'authentication' | 'security'
}
}