feat: add rate limit otp (#27402)

* feat: add rate limit otp

* Update apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx

Co-authored-by: Joel Lee <lee.yi.jie.joel@gmail.com>

* Update apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx

Co-authored-by: Joel Lee <lee.yi.jie.joel@gmail.com>

* fix: update rate limit otps

* Change the p to FormDescription element.

---------

Co-authored-by: Kang Ming <kang.ming1996@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
This commit is contained in:
authored and GitHub committed 2024-07-10 07:45:38 -07:00
1 parent 879a668c0c
commit fcd81a8d2f
1 file changed
+42
@@ -22,6 +22,7 @@ import {
Alert_Shadcn_,
Button,
FormControl_Shadcn_,
FormDescription_Shadcn_,
FormField_Shadcn_,
FormItem_Shadcn_,
Form_Shadcn_,
@@ -76,6 +77,10 @@ const RateLimits = () => {
.number()
.min(0, 'Must be not be lower than 0')
.max(32767, 'Must not be more than 32,767 an hour'),
RATE_LIMIT_OTP: z.coerce
.number()
.min(0, 'Must be not be lower than 0')
.max(32767, 'Must not be more than 32,767 an hour'),
})
const form = useForm<z.infer<typeof FormSchema>>({
@@ -85,6 +90,7 @@ const RateLimits = () => {
RATE_LIMIT_VERIFY: 0,
RATE_LIMIT_EMAIL_SENT: 0,
RATE_LIMIT_SMS_SENT: 0,
RATE_LIMIT_OTP: 0,
},
})
@@ -98,6 +104,7 @@ const RateLimits = () => {
'RATE_LIMIT_EMAIL_SENT',
'RATE_LIMIT_SMS_SENT',
'RATE_LIMIT_ANONYMOUS_USERS',
'RATE_LIMIT_OTP',
] as (keyof typeof payload)[]
params.forEach((param) => {
if (data[param] !== authConfig?.[param]) payload[param] = data[param]
@@ -114,6 +121,7 @@ const RateLimits = () => {
RATE_LIMIT_EMAIL_SENT: authConfig.RATE_LIMIT_EMAIL_SENT,
RATE_LIMIT_SMS_SENT: authConfig.RATE_LIMIT_SMS_SENT,
RATE_LIMIT_ANONYMOUS_USERS: authConfig.RATE_LIMIT_ANONYMOUS_USERS,
RATE_LIMIT_OTP: authConfig.RATE_LIMIT_OTP,
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -394,6 +402,40 @@ const RateLimits = () => {
/>
</FormSectionContent>
</FormSection>
<FormSection
id="otp"
header={
<FormSectionLabel
description={
<p className="text-foreground-light text-sm">
Number of sign up and sign-in requests that can be made per hour per IP
address (excludes anonymous users).
</p>
}
>
Rate limit for sign ups and sign ins
</FormSectionLabel>
}
>
<FormSectionContent loading={false}>
<FormField_Shadcn_
control={form.control}
name="RATE_LIMIT_OTP"
render={({ field }) => (
<FormItem_Shadcn_>
<FormControl_Shadcn_>
<Input_Shadcn_ type="number" {...field} disabled={!canUpdateConfig} />
</FormControl_Shadcn_>
{field.value > 0 && (
<FormDescription_Shadcn_ className="text-foreground-lighter">
This is equivalent to {field.value * 12} requests per hour
</FormDescription_Shadcn_>
)}
</FormItem_Shadcn_>
)}
/>
</FormSectionContent>
</FormSection>
</FormPanel>
</form>
</Form_Shadcn_>