Skip to content

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

fix: consolidate SMTP minimum interval into Rate Limits page (#51784)

Monica Khoury97bd456842ed
diff --git a/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx b/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
index 4679d8b0e20..b0a90619d4f 100644
--- a/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
+++ b/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
@@ -132,6 +132,10 @@ export const RateLimits = () => {
.number()
.min(0, 'Must be not be lower than 0')
.max(2147483647, 'Must not be more than 2,147,483,647 per hour'),
+ SMTP_MAX_FREQUENCY: z.coerce
+ .number()
+ .min(0, 'Must be not be lower than 0')
+ .max(32767, 'Must not be more than 32,767 seconds'),
})
const rateLimitForm = useForm<z.infer<typeof RateLimitFormSchema>>({
@@ -144,6 +148,7 @@ export const RateLimits = () => {
RATE_LIMIT_ANONYMOUS_USERS: 0,
RATE_LIMIT_OTP: 0,
RATE_LIMIT_WEB3: 0,
+ SMTP_MAX_FREQUENCY: 60,
},
})
@@ -153,10 +158,16 @@ export const RateLimits = () => {
})
const rateLimitVerify = useWatch({ control: rateLimitForm.control, name: 'RATE_LIMIT_VERIFY' })
const rateLimitOtp = useWatch({ control: rateLimitForm.control, name: 'RATE_LIMIT_OTP' })
+ const { dirtyFields: rateLimitDirtyFields } = rateLimitForm.formState
const onSubmitRateLimitForm = (data: z.infer<typeof RateLimitFormSchema>) => {
if (!projectRef) return console.error('Project ref is required')
+ if (rateLimitDirtyFields.SMTP_MAX_FREQUENCY && data.SMTP_MAX_FREQUENCY < 1) {
+ rateLimitForm.setError('SMTP_MAX_FREQUENCY', { message: 'Must be more than 0' })
+ return
+ }
+
const payload: Partial<z.infer<typeof RateLimitFormSchema>> = {}
const params = [
'RATE_LIMIT_TOKEN_REFRESH',
@@ -166,6 +177,7 @@ export const RateLimits = () => {
'RATE_LIMIT_ANONYMOUS_USERS',
'RATE_LIMIT_OTP',
'RATE_LIMIT_WEB3',
+ 'SMTP_MAX_FREQUENCY',
] as (keyof typeof payload)[]
params.forEach((param) => {
if (data[param] !== authConfig?.[param]) payload[param] = data[param]
@@ -187,6 +199,7 @@ export const RateLimits = () => {
RATE_LIMIT_ANONYMOUS_USERS: authConfig.RATE_LIMIT_ANONYMOUS_USERS,
RATE_LIMIT_OTP: authConfig.RATE_LIMIT_OTP,
RATE_LIMIT_WEB3: authConfig.RATE_LIMIT_WEB3 ?? 0,
+ SMTP_MAX_FREQUENCY: authConfig.SMTP_MAX_FREQUENCY,
})
ipForwardingForm.reset({
@@ -597,6 +610,70 @@ export const RateLimits = () => {
/>
</CardContent>
+ <CardContent>
+ <FormField
+ control={rateLimitForm.control}
+ name="SMTP_MAX_FREQUENCY"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Minimum interval per user"
+ description="Minimum time between emails sent to the same user. Only applies when Custom SMTP is configured."
+ >
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <FormControl>
+ <InputGroup>
+ <FormInputGroupInput
+ type="number"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig || !isSmtpEnabled(authConfig)}
+ />
+ <InputGroupAddon align="inline-end">
+ <InputGroupText>seconds</InputGroupText>
+ </InputGroupAddon>
+ </InputGroup>
+ </FormControl>
+ </TooltipTrigger>
+ {!canUpdateConfig || !isSmtpEnabled(authConfig) ? (
+ <TooltipContent side="left" className="w-80 p-4">
+ {!canUpdateConfig ? (
+ <>
+ <p className="font-medium">
+ You don't have permission to update this setting
+ </p>
+ <p className="mt-1">
+ You need additional permissions to update auth configuration
+ settings
+ </p>
+ </>
+ ) : (
+ <>
+ <p className="font-medium">
+ Custom SMTP is required to update this setting
+ </p>
+ <p className="mt-1">
+ This setting only applies when a custom SMTP provider is
+ configured
+ </p>
+ <div className="mt-3">
+ <Button asChild size="tiny">
+ <Link href={`/project/${projectRef}/auth/smtp`}>
+ View SMTP settings
+ </Link>
+ </Button>
+ </div>
+ </>
+ )}
+ </TooltipContent>
+ ) : null}
+ </Tooltip>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+
<CardFooter className="justify-end space-x-2">
{rateLimitForm.formState.isDirty && (
<Button onClick={() => rateLimitForm.reset()}>Cancel</Button>
diff --git a/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx b/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
index afbc5c6f3dc..2bc9dc5719b 100644
--- a/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
+++ b/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
@@ -12,11 +12,7 @@ import {
Form,
FormControl,
FormField,
- FormInputGroupInput,
Input,
- InputGroup,
- InputGroupAddon,
- InputGroupText,
Switch,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
@@ -62,15 +58,6 @@ const smtpEnabledSchema = z.object({
.min(1, 'Must be a valid port number more than 0')
.max(65535, 'Must be a valid port number no more than 65535')
),
- SMTP_MAX_FREQUENCY: preprocessEmptyNumberInput(
- z.coerce
- .number({
- required_error: 'Rate limit is required',
- invalid_type_error: 'Rate limit is required',
- })
- .min(1, 'Must be more than 0')
- .max(32767, 'Must not be more than 32,767 an hour')
- ),
SMTP_USER: z.string().trim().min(1, 'SMTP Username is required'),
SMTP_PASS: z.string().trim().optional(),
})
@@ -81,7 +68,6 @@ const smtpDisabledSchema = z.object({
SMTP_SENDER_NAME: z.string().optional(),
SMTP_HOST: z.string().optional(),
SMTP_PORT: preprocessEmptyNumberInput(z.coerce.number().optional()),
- SMTP_MAX_FREQUENCY: preprocessEmptyNumberInput(z.coerce.number().optional()),
SMTP_USER: z.string().optional(),
SMTP_PASS: z.string().optional(),
})
@@ -138,7 +124,6 @@ export const SmtpForm = () => {
SMTP_SENDER_NAME: '',
SMTP_HOST: '',
SMTP_PORT: undefined,
- SMTP_MAX_FREQUENCY: undefined,
SMTP_USER: '',
SMTP_PASS: '',
ENABLE_SMTP: false,
@@ -423,31 +408,6 @@ export const SmtpForm = () => {
)}
/>
- <FormField
- control={form.control}
- name="SMTP_MAX_FREQUENCY"
- render={({ field }) => (
- <FormItemLayout
- label="Minimum interval per user"
- description="The minimum time in seconds between emails before another email can be sent to the same user."
- >
- <FormControl>
- <InputGroup>
- <FormInputGroupInput
- type="number"
- value={field.value}
- onChange={(e) => field.onChange(e.target.value)}
- disabled={!canUpdateConfig}
- />
- <InputGroupAddon align="inline-end">
- <InputGroupText>seconds</InputGroupText>
- </InputGroupAddon>
- </InputGroup>
- </FormControl>
- </FormItemLayout>
- )}
- />
-
<FormField
control={form.control}
name="SMTP_USER"
diff --git a/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts b/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts
index bfacbe776b9..ca2301bb0e0 100644
--- a/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts
+++ b/apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts
@@ -27,6 +27,5 @@ export const generateFormValues = (config?: Partial<AuthConfig>): Partial<AuthCo
SMTP_HOST: config?.SMTP_HOST ?? '',
SMTP_PASS: '',
SMTP_PORT: config?.SMTP_PORT ?? '465',
- SMTP_MAX_FREQUENCY: config?.SMTP_MAX_FREQUENCY ?? 60,
}
}