Skip to content

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

Updating authentication rate limits and session pages (#33957)

Saxon Fletcher83bcb1e89120
diff --git a/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx b/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
index eb22382e5e5..6d484a4026f 100644
--- a/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
+++ b/apps/studio/components/interfaces/Auth/RateLimits/RateLimits.tsx
@@ -8,10 +8,7 @@ import * as z from 'zod'
import { useParams } from 'common'
import AlertError from 'components/ui/AlertError'
-import { FormActions } from 'components/ui/Forms/FormActions'
-import { FormHeader } from 'components/ui/Forms/FormHeader'
-import { FormPanel } from 'components/ui/Forms/FormPanel'
-import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'
+import NoPermission from 'components/ui/NoPermission'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useAuthConfigQuery } from 'data/auth/auth-config-query'
import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'
@@ -21,20 +18,26 @@ import {
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
+ Card,
+ CardContent,
+ CardFooter,
FormControl_Shadcn_,
- FormDescription_Shadcn_,
FormField_Shadcn_,
- FormItem_Shadcn_,
Form_Shadcn_,
Input_Shadcn_,
WarningIcon,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { isSmtpEnabled } from '../SmtpForm/SmtpForm.utils'
+import { ScaffoldSection } from 'components/layouts/Scaffold'
const RateLimits = () => {
- const formId = 'auth-rate-limits-form'
const { ref: projectRef } = useParams()
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
+ const canReadConfig = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
const {
data: authConfig,
@@ -90,6 +93,7 @@ const RateLimits = () => {
RATE_LIMIT_VERIFY: 0,
RATE_LIMIT_EMAIL_SENT: 0,
RATE_LIMIT_SMS_SENT: 0,
+ RATE_LIMIT_ANONYMOUS_USERS: 0,
RATE_LIMIT_OTP: 0,
},
})
@@ -127,314 +131,325 @@ const RateLimits = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSuccess])
- return (
- <div>
- {isError && <AlertError subject="Failed to retrieve auth config rate limits" error={error} />}
+ if (isError) {
+ return <AlertError subject="Failed to retrieve auth config rate limits" error={error} />
+ }
- {isLoading && <GenericSkeletonLoader />}
+ if (!canReadConfig) {
+ return <NoPermission resourceText="view auth configuration settings" />
+ }
- {isSuccess && (
- <Form_Shadcn_ {...form}>
- <form id={formId} className="space-y-4" onSubmit={form.handleSubmit(onSubmit)}>
- <FormPanel
- footer={
- <div className="flex py-4 px-8">
- <FormActions
- form={formId}
- isSubmitting={isUpdatingConfig}
- hasChanges={form.formState.isDirty}
- handleReset={() => form.reset()}
- disabled={!canUpdateConfig}
- helper={
- !canUpdateConfig
- ? 'You need additional permissions to update authentication settings'
- : undefined
- }
- />
- </div>
- }
- >
- <FormSection
- id="email-sent"
- header={
- <FormSectionLabel
- description={
- <p className="text-foreground-light text-sm">
- Number of emails that can be sent per hour from your project
- </p>
- }
+ if (isLoading) {
+ return <GenericSkeletonLoader />
+ }
+
+ return (
+ <ScaffoldSection isFullWidth>
+ <Form_Shadcn_ {...form}>
+ <form className="space-y-4" onSubmit={form.handleSubmit(onSubmit)}>
+ <Card>
+ <CardContent className="pt-6">
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_EMAIL_SENT"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for sending emails"
+ description="Number of emails that can be sent per hour from your project"
>
- Rate limit for sending emails
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false}>
- <FormField_Shadcn_
- control={form.control}
- name="RATE_LIMIT_EMAIL_SENT"
- render={({ field }) => (
- <FormItem_Shadcn_ className="flex flex-col gap-y-2">
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
<Input_Shadcn_
- disabled={!canUpdateConfig || !canUpdateEmailLimit}
type="number"
+ className="w-24"
+ min={0}
{...field}
+ disabled={!canUpdateConfig || !canUpdateEmailLimit}
/>
</FormControl_Shadcn_>
- {!authConfig.EXTERNAL_EMAIL_ENABLED ? (
- <Alert_Shadcn_>
- <WarningIcon />
- <AlertTitle_Shadcn_>
- Email-based logins are not enabled for your project
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_ className="flex flex-col gap-y-3">
- <p className="!leading-tight">
+ </TooltipTrigger>
+ {!canUpdateConfig || !canUpdateEmailLimit ? (
+ <TooltipContent side="left" className="w-80 p-4">
+ {!authConfig.EXTERNAL_EMAIL_ENABLED ? (
+ <>
+ <p className="font-medium">
+ Email-based logins are not enabled for your project
+ </p>
+ <p className="mt-1">
Enable email-based logins to update this rate limit
</p>
- <Button asChild type="default" className="w-min">
- <Link href={`/project/${projectRef}/auth/providers`}>
- View auth providers
- </Link>
- </Button>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- ) : !isSmtpEnabled(authConfig) ? (
- <Alert_Shadcn_>
- <WarningIcon />
- <AlertTitle_Shadcn_>
- Custom SMTP provider is required to update this configuration
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_ className="flex flex-col gap-y-3">
- <p className="!leading-tight">
+ <div className="mt-3">
+ <Button asChild type="default" size="tiny">
+ <Link href={`/project/${projectRef}/auth/providers`}>
+ View auth providers
+ </Link>
+ </Button>
+ </div>
+ </>
+ ) : (
+ <>
+ <p className="font-medium">
+ Custom SMTP provider is required to update this configuration
+ </p>
+ <p className="mt-1">
The built-in email service has a fixed rate limit. You will need to
set up your own custom SMTP provider to update your email rate limit
</p>
- <Button asChild type="default" className="w-min">
- <Link href={`/project/${projectRef}/settings/auth`}>
- View SMTP settings
- </Link>
- </Button>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- ) : null}
- </FormItem_Shadcn_>
- )}
- />
- </FormSectionContent>
- </FormSection>
+ <div className="mt-3">
+ <Button asChild type="default" size="tiny">
+ <Link href={`/project/${projectRef}/settings/auth`}>
+ View SMTP settings
+ </Link>
+ </Button>
+ </div>
+ </>
+ )}
+ </TooltipContent>
+ ) : null}
+ </Tooltip>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
- <FormSection
- id="sms-sent"
- header={
- <FormSectionLabel
- description={
- <p className="text-foreground-light text-sm">
- Number of SMS messages that can be sent per hour from your project
- </p>
- }
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_SMS_SENT"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for sending SMS messages"
+ description="Number of SMS messages that can be sent per hour from your project"
>
- Rate limit for sending SMS messages
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false}>
- <FormField_Shadcn_
- control={form.control}
- name="RATE_LIMIT_SMS_SENT"
- render={({ field }) => (
- <FormItem_Shadcn_ className="flex flex-col gap-y-2">
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
<Input_Shadcn_
- disabled={!canUpdateConfig || !canUpdateSMSRateLimit}
type="number"
+ className="w-24"
+ min={0}
{...field}
+ disabled={!canUpdateConfig || !canUpdateSMSRateLimit}
/>
</FormControl_Shadcn_>
- {!canUpdateSMSRateLimit && (
- <Alert_Shadcn_>
- <WarningIcon />
- <AlertTitle_Shadcn_>
- Phone-based logins are not enabled for your project
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_ className="flex flex-col gap-y-3">
- <p className="!leading-tight">
- Enable phone-based logins to update this rate limit
- </p>
- <Button asChild type="default" className="w-min">
- <Link href={`/project/${projectRef}/auth/providers`}>
- View auth providers
- </Link>
- </Button>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
- </FormItem_Shadcn_>
- )}
- />
- </FormSectionContent>
- </FormSection>
+ </TooltipTrigger>
+ {!canUpdateConfig || !canUpdateSMSRateLimit ? (
+ <TooltipContent side="left" className="w-80 p-4">
+ <p className="font-medium">
+ Phone-based logins are not enabled for your project
+ </p>
+ <p className="mt-1">
+ Enable phone-based logins to update this rate limit
+ </p>
+ <div className="mt-3">
+ <Button asChild type="default" size="tiny">
+ <Link href={`/project/${projectRef}/auth/providers`}>
+ View auth providers
+ </Link>
+ </Button>
+ </div>
+ </TooltipContent>
+ ) : null}
+ </Tooltip>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
- <FormSection
- id="token-refresh"
- header={
- <FormSectionLabel
- description={
- <p className="text-foreground-light text-sm">
- Number of sessions that can be refreshed in a 5 minute interval per IP
- address.
- </p>
- }
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_TOKEN_REFRESH"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for token refreshes"
+ description="Number of sessions that can be refreshed in a 5 minute interval per IP address"
>
- Rate limit for token refreshes
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false}>
- <FormField_Shadcn_
- control={form.control}
- name="RATE_LIMIT_TOKEN_REFRESH"
- render={({ field }) => (
- <FormItem_Shadcn_>
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
- <Input_Shadcn_ type="number" {...field} disabled={!canUpdateConfig} />
+ <Input_Shadcn_
+ type="number"
+ className="w-24"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig}
+ />
</FormControl_Shadcn_>
- {field.value > 0 && (
- <>
- <p className="text-foreground-lighter text-sm">
- This is equivalent to {field.value * 12} requests per hour
- </p>
- </>
- )}
- </FormItem_Shadcn_>
+ </TooltipTrigger>
+ {!canUpdateConfig && (
+ <TooltipContent side="left" className="w-80 p-4">
+ <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>
+ </TooltipContent>
+ )}
+ </Tooltip>
+ {form.watch('RATE_LIMIT_TOKEN_REFRESH') > 0 && (
+ <p className="text-foreground-lighter text-sm mt-2">
+ {form.watch('RATE_LIMIT_TOKEN_REFRESH') * 12} requests per hour
+ </p>
)}
- />
- </FormSectionContent>
- </FormSection>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
- <FormSection
- id="verify"
- header={
- <FormSectionLabel
- description={
- <p className="text-foreground-light text-sm">
- Number of OTP/Magic link verifications that can be made in a 5 minute
- interval per IP address.
- </p>
- }
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_VERIFY"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for token verifications"
+ description="Number of OTP/Magic link verifications that can be made in a 5 minute interval per IP address"
>
- Rate limit for token verifications
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false}>
- <FormField_Shadcn_
- control={form.control}
- name="RATE_LIMIT_VERIFY"
- render={({ field }) => (
- <FormItem_Shadcn_>
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
- <Input_Shadcn_ type="number" {...field} disabled={!canUpdateConfig} />
+ <Input_Shadcn_
+ type="number"
+ className="w-24"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig}
+ />
</FormControl_Shadcn_>
- {field.value > 0 && (
- <p className="text-foreground-lighter text-sm">
- This is equivalent to {field.value * 12} requests per hour
+ </TooltipTrigger>
+ {!canUpdateConfig && (
+ <TooltipContent side="left" className="w-80 p-4">
+ <p className="font-medium">
+ You don't have permission to update this setting
</p>
- )}
- </FormItem_Shadcn_>
+ <p className="mt-1">
+ You need additional permissions to update auth configuration settings
+ </p>
+ </TooltipContent>
+ )}
+ </Tooltip>
+ {form.watch('RATE_LIMIT_VERIFY') > 0 && (
+ <p className="text-foreground-lighter text-sm mt-2">
+ {form.watch('RATE_LIMIT_VERIFY') * 12} requests per hour
+ </p>
)}
- />
- </FormSectionContent>
- </FormSection>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
- <FormSection
- id="anonymous-users"
- header={
- <FormSectionLabel
- description={
- <p className="text-foreground-light text-sm">
- Number of anonymous sign-ins that can be made per hour per IP address.
- </p>
- }
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_ANONYMOUS_USERS"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for anonymous users"
+ description="Number of anonymous sign-ins that can be made per hour per IP address"
>
- Rate limit for anonymous users
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false}>
- <FormField_Shadcn_
- control={form.control}
- name="RATE_LIMIT_ANONYMOUS_USERS"
- render={({ field }) => (
- <FormItem_Shadcn_ className="flex flex-col gap-y-2">
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
<Input_Shadcn_
- disabled={!canUpdateConfig || !canUpdateAnonymousUsersRateLimit}
type="number"
+ className="w-24"
+ min={0}
{...field}
+ disabled={!canUpdateConfig || !canUpdateAnonymousUsersRateLimit}
/>
</FormControl_Shadcn_>
- {!canUpdateAnonymousUsersRateLimit && (
- <Alert_Shadcn_>
- <WarningIcon />
- <AlertTitle_Shadcn_>
- Anonymous logins are not enabled for your project
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_ className="flex flex-col gap-y-3">
- <p className="!leading-tight">
- Enable anonymous logins to update this rate limit
- </p>
- <Button asChild type="default" className="w-min">
- <Link href={`/project/${projectRef}/settings/auth`}>
- View auth settings
- </Link>
- </Button>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
- </FormItem_Shadcn_>
- )}
- />
- </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 in a 5 minute
- interval per IP address (excludes anonymous users).
- </p>
- }
+ </TooltipTrigger>
+ {!canUpdateConfig || !canUpdateAnonymousUsersRateLimit ? (
+ <TooltipContent side="left" className="w-80 p-4">
+ <p className="font-medium">
+ Anonymous logins are not enabled for your project
+ </p>
+ <p className="mt-1">Enable anonymous logins to update this rate limit</p>
+ <div className="mt-3">
+ <Button asChild type="default" size="tiny">
+ <Link href={`/project/${projectRef}/settings/auth`}>
+ View auth settings
+ </Link>
+ </Button>
+ </div>
+ </TooltipContent>
+ ) : null}
+ </Tooltip>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="RATE_LIMIT_OTP"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Rate limit for sign ups and sign ins"
+ description="Number of sign up and sign-in requests that can be made in a 5 minute interval per IP address (excludes anonymous users)"
>
- 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_>
+ <Tooltip>
+ <TooltipTrigger asChild>
<FormControl_Shadcn_>
- <Input_Shadcn_ type="number" {...field} disabled={!canUpdateConfig} />
+ <Input_Shadcn_
+ type="number"
+ className="w-24"
+ min={0}
+ {...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_>
+ </TooltipTrigger>
+ {!canUpdateConfig && (
+ <TooltipContent side="left" className="w-80 p-4">
+ <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>
+ </TooltipContent>
+ )}
+ </Tooltip>
+ {form.watch('RATE_LIMIT_OTP') > 0 && (
+ <p className="text-foreground-lighter text-sm mt-2">
+ {form.watch('RATE_LIMIT_OTP') * 12} requests per hour
+ </p>
)}
- />
- </FormSectionContent>
- </FormSection>
- </FormPanel>
- </form>
- </Form_Shadcn_>
- )}
- </div>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+
+ <CardFooter className="justify-end space-x-2">
+ {form.formState.isDirty && (
+ <Button type="default" onClick={() => form.reset()}>
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={!canUpdateConfig || isUpdatingConfig || !form.formState.isDirty}
+ loading={isUpdatingConfig}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ </ScaffoldSection>
)
}
diff --git a/apps/studio/components/interfaces/Auth/SessionsAuthSettingsForm/SessionsAuthSettingsForm.tsx b/apps/studio/components/interfaces/Auth/SessionsAuthSettingsForm/SessionsAuthSettingsForm.tsx
index d7c7a9dbf20..a580978373d 100644
--- a/apps/studio/components/interfaces/Auth/SessionsAuthSettingsForm/SessionsAuthSettingsForm.tsx
+++ b/apps/studio/components/interfaces/Auth/SessionsAuthSettingsForm/SessionsAuthSettingsForm.tsx
@@ -1,13 +1,12 @@
+import { yupResolver } from '@hookform/resolvers/yup'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useEffect } from 'react'
+import { useEffect, useState } from 'react'
+import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { boolean, number, object } from 'yup'
import { useParams } from 'common'
-import { FormActions } from 'components/ui/Forms/FormActions'
-import { FormHeader } from 'components/ui/Forms/FormHeader'
-import { FormPanel } from 'components/ui/Forms/FormPanel'
-import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'
+import { ScaffoldSection, ScaffoldSectionTitle } from 'components/layouts/Scaffold'
import NoPermission from 'components/ui/NoPermission'
import UpgradeToPro from 'components/ui/UpgradeToPro'
import { useAuthConfigQuery } from 'data/auth/auth-config-query'
@@ -16,16 +15,23 @@ import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-que
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { IS_PLATFORM } from 'lib/constants'
-
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Alert_Shadcn_,
- Form,
- InputNumber,
- Toggle,
+ Button,
+ Card,
+ CardContent,
+ CardFooter,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Form_Shadcn_,
+ Input_Shadcn_,
+ PrePostTab,
+ Switch,
WarningIcon,
} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
function HoursOrNeverText({ value }: { value: number }) {
if (value === 0) {
@@ -37,11 +43,14 @@ function HoursOrNeverText({ value }: { value: number }) {
}
}
-const schema = object({
+const refreshTokenSchema = object({
REFRESH_TOKEN_ROTATION_ENABLED: boolean().required(),
SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: number()
.min(0, 'Must be a value more than 0')
.required('Must have a Reuse Interval value'),
+})
+
+const userSessionsSchema = object({
SESSIONS_TIMEBOX: number().min(0, 'Must be a positive number'),
SESSIONS_INACTIVITY_TIMEOUT: number().min(0, 'Must be a positive number'),
SESSIONS_SINGLE_PER_USER: boolean(),
@@ -49,16 +58,13 @@ const schema = object({
const SessionsAuthSettingsForm = () => {
const { ref: projectRef } = useParams()
- const {
- data: authConfig,
- error: authConfigError,
- isLoading,
- isError,
- isSuccess,
- } = useAuthConfigQuery({ projectRef })
+ const { data: authConfig, error: authConfigError, isError } = useAuthConfigQuery({ projectRef })
const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
- const formId = 'auth-config-sessions-form'
+ // Separate loading states for each form
+ const [isUpdatingRefreshTokens, setIsUpdatingRefreshTokens] = useState(false)
+ const [isUpdatingUserSessions, setIsUpdatingUserSessions] = useState(false)
+
const canReadConfig = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
@@ -70,26 +76,76 @@ const SessionsAuthSettingsForm = () => {
const isProPlanAndUp = isSuccessSubscription && subscription?.plan?.id !== 'free'
const promptProPlanUpgrade = IS_PLATFORM && !isProPlanAndUp
- const INITIAL_VALUES = {
- REFRESH_TOKEN_ROTATION_ENABLED: authConfig?.REFRESH_TOKEN_ROTATION_ENABLED || false,
- SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: authConfig?.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,
- SESSIONS_TIMEBOX: authConfig?.SESSIONS_TIMEBOX || 0,
- SESSIONS_INACTIVITY_TIMEOUT: authConfig?.SESSIONS_INACTIVITY_TIMEOUT || 0,
- SESSIONS_SINGLE_PER_USER: authConfig?.SESSIONS_SINGLE_PER_USER || false,
+ const refreshTokenForm = useForm({
+ resolver: yupResolver(refreshTokenSchema),
+ defaultValues: {
+ REFRESH_TOKEN_ROTATION_ENABLED: false,
+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: 0,
+ },
+ })
+
+ const userSessionsForm = useForm({
+ resolver: yupResolver(userSessionsSchema),
+ defaultValues: {
+ SESSIONS_TIMEBOX: 0,
+ SESSIONS_INACTIVITY_TIMEOUT: 0,
+ SESSIONS_SINGLE_PER_USER: false,
+ },
+ })
+
+ useEffect(() => {
+ if (authConfig) {
+ // Only reset forms if they're not currently being updated
+ if (!isUpdatingRefreshTokens) {
+ refreshTokenForm.reset({
+ REFRESH_TOKEN_ROTATION_ENABLED: authConfig.REFRESH_TOKEN_ROTATION_ENABLED || false,
+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: authConfig.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,
+ })
+ }
+
+ if (!isUpdatingUserSessions) {
+ userSessionsForm.reset({
+ SESSIONS_TIMEBOX: authConfig.SESSIONS_TIMEBOX || 0,
+ SESSIONS_INACTIVITY_TIMEOUT: authConfig.SESSIONS_INACTIVITY_TIMEOUT || 0,
+ SESSIONS_SINGLE_PER_USER: authConfig.SESSIONS_SINGLE_PER_USER || false,
+ })
+ }
+ }
+ }, [authConfig, isUpdatingRefreshTokens, isUpdatingUserSessions])
+
+ const onSubmitRefreshTokens = (values: any) => {
+ const payload = { ...values }
+ setIsUpdatingRefreshTokens(true)
+
+ updateAuthConfig(
+ { projectRef: projectRef!, config: payload },
+ {
+ onError: (error) => {
+ toast.error(`Failed to update refresh token settings: ${error?.message}`)
+ setIsUpdatingRefreshTokens(false)
+ },
+ onSuccess: () => {
+ toast.success('Successfully updated refresh token settings')
+ setIsUpdatingRefreshTokens(false)
+ },
+ }
+ )
}
- const onSubmit = (values: any, { resetForm }: any) => {
+ const onSubmitUserSessions = (values: any) => {
const payload = { ...values }
+ setIsUpdatingUserSessions(true)
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
onError: (error) => {
- toast.error(`Failed to update settings: ${error?.message}`)
+ toast.error(`Failed to update user session settings: ${error?.message}`)
+ setIsUpdatingUserSessions(false)
},
onSuccess: () => {
- toast.success('Successfully updated settings')
- resetForm({ values: values, initialValues: values })
+ toast.success('Successfully updated user session settings')
+ setIsUpdatingUserSessions(false)
},
}
)
@@ -110,108 +166,204 @@ const SessionsAuthSettingsForm = () => {
}
return (
- <Form id={formId} initialValues={INITIAL_VALUES} onSubmit={onSubmit} validationSchema={schema}>
- {({ handleReset, resetForm, values, initialValues }: any) => {
- const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
-
- // Form is reset once remote data is loaded in store
- // eslint-disable-next-line react-hooks/rules-of-hooks
- useEffect(() => {
- if (isSuccess) resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })
- }, [isSuccess])
-
- return (
- <>
- <FormPanel
- disabled={true}
- footer={
- <div className="flex py-4 px-8">
- <FormActions
- form={formId}
- isSubmitting={isUpdatingConfig}
- hasChanges={hasChanges}
- handleReset={handleReset}
- disabled={!canUpdateConfig}
- helper={
- !canUpdateConfig
- ? 'You need additional permissions to update authentication settings'
- : undefined
- }
- />
- </div>
- }
- >
- <FormSection header={<FormSectionLabel>Refresh Tokens</FormSectionLabel>}>
- <FormSectionContent loading={isLoading}>
- <Toggle
- id="REFRESH_TOKEN_ROTATION_ENABLED"
- size="small"
- label="Detect and revoke potentially compromised refresh tokens"
- layout="flex"
- descriptionText="Prevent replay attacks from potentially compromised refresh tokens."
- disabled={!canUpdateConfig}
- />
- {values.REFRESH_TOKEN_ROTATION_ENABLED && (
- <InputNumber
- id="SECURITY_REFRESH_TOKEN_REUSE_INTERVAL"
- size="small"
- min={0}
- label="Refresh token reuse interval"
- descriptionText="Time interval where the same refresh token can be used multiple times to request for an access token. Recommendation: 10 seconds."
- actions={<span className="mr-3 text-foreground-lighter">seconds</span>}
- disabled={!canUpdateConfig}
- />
+ <>
+ <ScaffoldSection isFullWidth>
+ <ScaffoldSectionTitle className="mb-4">Refresh Tokens</ScaffoldSectionTitle>
+
+ <Form_Shadcn_ {...refreshTokenForm}>
+ <form
+ onSubmit={refreshTokenForm.handleSubmit(onSubmitRefreshTokens)}
+ className="space-y-4"
+ >
+ <Card>
+ <CardContent className="pt-6">
+ <FormField_Shadcn_
+ control={refreshTokenForm.control}
+ name="REFRESH_TOKEN_ROTATION_ENABLED"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Detect and revoke potentially compromised refresh tokens"
+ description="Prevent replay attacks from potentially compromised refresh tokens."
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={!canUpdateConfig}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
)}
- </FormSectionContent>
- </FormSection>
+ />
+ </CardContent>
+ {refreshTokenForm.watch('REFRESH_TOKEN_ROTATION_ENABLED') && (
+ <CardContent>
+ <FormField_Shadcn_
+ control={refreshTokenForm.control}
+ name="SECURITY_REFRESH_TOKEN_REUSE_INTERVAL"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Refresh token reuse interval"
+ description="Time interval where the same refresh token can be used multiple times to request for an access token. Recommendation: 10 seconds."
+ >
+ <FormControl_Shadcn_>
+ <PrePostTab postTab="seconds">
+ <Input_Shadcn_
+ type="number"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig}
+ />
+ </PrePostTab>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+ )}
+ <CardFooter className="justify-end space-x-2">
+ {refreshTokenForm.formState.isDirty && (
+ <Button type="default" onClick={() => refreshTokenForm.reset()}>
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={
+ !canUpdateConfig ||
+ isUpdatingRefreshTokens ||
+ !refreshTokenForm.formState.isDirty
+ }
+ loading={isUpdatingRefreshTokens}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ </ScaffoldSection>
- <FormSection header={<FormSectionLabel>User Sessions</FormSectionLabel>}>
- <FormSectionContent loading={isLoading}>
- {promptProPlanUpgrade && (
+ <ScaffoldSection isFullWidth>
+ <ScaffoldSectionTitle className="mb-4">User Sessions</ScaffoldSectionTitle>
+
+ <Form_Shadcn_ {...userSessionsForm}>
+ <form
+ onSubmit={userSessionsForm.handleSubmit(onSubmitUserSessions)}
+ className="space-y-4"
+ >
+ <Card>
+ <CardContent>
+ {promptProPlanUpgrade && (
+ <div className="mb-4">
<UpgradeToPro
primaryText="Upgrade to Pro"
secondaryText="Configuring user sessions requires the Pro Plan."
/>
+ </div>
+ )}
+
+ <FormField_Shadcn_
+ control={userSessionsForm.control}
+ name="SESSIONS_SINGLE_PER_USER"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Enforce single session per user"
+ description="If enabled, all but a user's most recently active session will be terminated."
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={!canUpdateConfig || !isProPlanAndUp}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
)}
- <Toggle
- id="SESSIONS_SINGLE_PER_USER"
- size="small"
- label="Enforce single session per user"
- layout="flex"
- descriptionText="If enabled, all but a user's most recently active session will be terminated."
- disabled={!canUpdateConfig || !isProPlanAndUp}
- />
- <InputNumber
- id="SESSIONS_TIMEBOX"
- size="small"
- label="Time-box user sessions"
- descriptionText="The amount of time before a user is forced to sign in again. Use 0 for never"
- actions={
- <span className="mr-3 text-foreground-lighter">
- <HoursOrNeverText value={values.SESSIONS_TIMEBOX} />
- </span>
- }
- disabled={!canUpdateConfig || !isProPlanAndUp}
- />
- <InputNumber
- id="SESSIONS_INACTIVITY_TIMEOUT"
- size="small"
- label="Inactivity timeout"
- descriptionText="The amount of time a user needs to be inactive to be forced to sign in again. Use 0 for never."
- actions={
- <span className="mr-3 text-foreground-lighter">
- <HoursOrNeverText value={values.SESSIONS_INACTIVITY_TIMEOUT} />
- </span>
- }
- disabled={!canUpdateConfig || !isProPlanAndUp}
- />
- </FormSectionContent>
- </FormSection>
- </FormPanel>
- </>
- )
- }}
- </Form>
+ />
+ </CardContent>
+
+ <CardContent>
+ <FormField_Shadcn_
+ control={userSessionsForm.control}
+ name="SESSIONS_TIMEBOX"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Time-box user sessions"
+ description="The amount of time before a user is forced to sign in again. Use 0 for never."
+ >
+ <div className="flex items-center">
+ <FormControl_Shadcn_>
+ <PrePostTab postTab={<HoursOrNeverText value={field.value || 0} />}>
+ <Input_Shadcn_
+ type="number"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig || !isProPlanAndUp}
+ />
+ </PrePostTab>
+ </FormControl_Shadcn_>
+ </div>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+
+ <CardContent>
+ <FormField_Shadcn_
+ control={userSessionsForm.control}
+ name="SESSIONS_INACTIVITY_TIMEOUT"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Inactivity timeout"
+ description="The amount of time a user needs to be inactive to be forced to sign in again. Use 0 for never."
+ >
+ <div className="flex items-center">
+ <FormControl_Shadcn_>
+ <PrePostTab postTab={<HoursOrNeverText value={field.value || 0} />}>
+ <Input_Shadcn_
+ type="number"
+ min={0}
+ {...field}
+ disabled={!canUpdateConfig || !isProPlanAndUp}
+ />
+ </PrePostTab>
+ </FormControl_Shadcn_>
+ </div>
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+ <CardFooter className="justify-end space-x-2">
+ {userSessionsForm.formState.isDirty && (
+ <Button type="default" onClick={() => userSessionsForm.reset()}>
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={
+ !canUpdateConfig ||
+ isUpdatingUserSessions ||
+ !userSessionsForm.formState.isDirty
+ }
+ loading={isUpdatingUserSessions}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ </ScaffoldSection>
+ </>
)
}
diff --git a/apps/studio/pages/project/[ref]/auth/rate-limits.tsx b/apps/studio/pages/project/[ref]/auth/rate-limits.tsx
index 2043aec5ba0..6676aaf147e 100644
--- a/apps/studio/pages/project/[ref]/auth/rate-limits.tsx
+++ b/apps/studio/pages/project/[ref]/auth/rate-limits.tsx
@@ -1,54 +1,57 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { ReactNode } from 'react'
+import { useParams } from 'common'
import RateLimits from 'components/interfaces/Auth/RateLimits/RateLimits'
import AuthLayout from 'components/layouts/AuthLayout/AuthLayout'
-import {
- ScaffoldHeader,
- ScaffoldContainer,
- ScaffoldDescription,
- ScaffoldTitle,
-} from 'components/layouts/Scaffold'
+import DefaultLayout from 'components/layouts/DefaultLayout'
+import { PageLayout } from 'components/layouts/PageLayout/PageLayout'
+import { ScaffoldContainer } from 'components/layouts/Scaffold'
import { DocsButton } from 'components/ui/DocsButton'
import NoPermission from 'components/ui/NoPermission'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
import type { NextPageWithLayout } from 'types'
-import DefaultLayout from 'components/layouts/DefaultLayout'
-const PageLayout: NextPageWithLayout = () => {
- const canReadAuthSettings = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
+interface RateLimitsLayoutProps {
+ children: ReactNode
+}
+
+export const RateLimitsLayout = ({ children }: RateLimitsLayoutProps) => {
+ const { ref } = useParams()
+
+ return (
+ <DefaultLayout>
+ <AuthLayout>
+ <PageLayout
+ title="Rate Limits"
+ subtitle="Safeguard against bursts of incoming traffic to prevent abuse and maximize stability"
+ primaryActions={
+ <DocsButton href="https://supabase.com/docs/guides/platform/going-into-prod#rate-limiting-resource-allocation--abuse-prevention" />
+ }
+ >
+ {children}
+ </PageLayout>
+ </AuthLayout>
+ </DefaultLayout>
+ )
+}
+
+const RateLimitsPage: NextPageWithLayout = () => {
const isPermissionsLoaded = usePermissionsLoaded()
+ const canReadAuthSettings = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
if (isPermissionsLoaded && !canReadAuthSettings) {
return <NoPermission isFullPage resourceText="access your project's auth rate limit settings" />
- } else {
- return (
- <div>
- <ScaffoldHeader className="pb-0">
- <ScaffoldContainer id="auth-page-top" className="flex items-center justify-between">
- <div>
- <ScaffoldTitle>Rate Limits</ScaffoldTitle>
- <ScaffoldDescription>
- Safeguard against bursts of incoming traffic to prevent abuse and maximize stability
- </ScaffoldDescription>
- </div>
- <DocsButton href="https://supabase.com/docs/guides/platform/going-into-prod#rate-limiting-resource-allocation--abuse-prevention" />
- </ScaffoldContainer>
- </ScaffoldHeader>
-
- <ScaffoldContainer className="my-8 space-y-8">
- <RateLimits />
- </ScaffoldContainer>
- </div>
- )
}
-}
-PageLayout.getLayout = (page) => {
return (
- <DefaultLayout>
- <AuthLayout>{page}</AuthLayout>
- </DefaultLayout>
+ <ScaffoldContainer>
+ {!isPermissionsLoaded ? <GenericSkeletonLoader /> : <RateLimits />}
+ </ScaffoldContainer>
)
}
-export default PageLayout
+RateLimitsPage.getLayout = (page) => <RateLimitsLayout>{page}</RateLimitsLayout>
+
+export default RateLimitsPage
diff --git a/apps/studio/pages/project/[ref]/auth/sessions.tsx b/apps/studio/pages/project/[ref]/auth/sessions.tsx
index 7dd24438315..b7b4298a79d 100644
--- a/apps/studio/pages/project/[ref]/auth/sessions.tsx
+++ b/apps/studio/pages/project/[ref]/auth/sessions.tsx
@@ -1,44 +1,56 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { ReactNode } from 'react'
-import { SessionsAuthSettingsForm, SmtpForm, ThirdPartyAuthForm } from 'components/interfaces/Auth'
+import { SessionsAuthSettingsForm } from 'components/interfaces/Auth'
import AuthLayout from 'components/layouts/AuthLayout/AuthLayout'
import DefaultLayout from 'components/layouts/DefaultLayout'
-import { ScaffoldContainer, ScaffoldHeader, ScaffoldTitle } from 'components/layouts/Scaffold'
+import { PageLayout } from 'components/layouts/PageLayout/PageLayout'
+import { ScaffoldContainer } from 'components/layouts/Scaffold'
import NoPermission from 'components/ui/NoPermission'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
import type { NextPageWithLayout } from 'types'
-const PageLayout: NextPageWithLayout = () => {
- const isPermissionsLoaded = usePermissionsLoaded()
- // TODO: check if these permissions cover third party auth as well
- const canReadAuthSettings = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
+interface SessionsLayoutProps {
+ children: ReactNode
+}
+export const SessionsLayout = ({ children }: SessionsLayoutProps) => {
return (
- <>
- <ScaffoldContainer>
- <ScaffoldHeader>
- <ScaffoldTitle>Sessions</ScaffoldTitle>
- </ScaffoldHeader>
- </ScaffoldContainer>
- <ScaffoldContainer className="flex flex-col gap-10" bottomPadding>
- {!isPermissionsLoaded ? (
- <GenericSkeletonLoader />
- ) : !canReadAuthSettings ? (
- <NoPermission isFullPage resourceText="access your project's authentication settings" />
- ) : (
- <SessionsAuthSettingsForm />
- )}
- </ScaffoldContainer>
- </>
+ <DefaultLayout>
+ <AuthLayout>
+ <PageLayout
+ title="User Sessions"
+ subtitle="Configure settings for user sessions and refresh tokens"
+ >
+ {children}
+ </PageLayout>
+ </AuthLayout>
+ </DefaultLayout>
)
}
-PageLayout.getLayout = (page) => {
+const SessionsPage: NextPageWithLayout = () => {
+ const isPermissionsLoaded = usePermissionsLoaded()
+ const canReadAuthSettings = useCheckPermissions(PermissionAction.READ, 'custom_config_gotrue')
+
+ if (isPermissionsLoaded && !canReadAuthSettings) {
+ return <NoPermission isFullPage resourceText="access your project's authentication settings" />
+ }
+
return (
- <DefaultLayout>
- <AuthLayout>{page}</AuthLayout>
- </DefaultLayout>
+ <ScaffoldContainer>
+ {!isPermissionsLoaded ? (
+ <div className="mt-12">
+ <GenericSkeletonLoader />
+ </div>
+ ) : (
+ <SessionsAuthSettingsForm />
+ )}
+ </ScaffoldContainer>
)
}
-export default PageLayout
+
+SessionsPage.getLayout = (page) => <SessionsLayout>{page}</SessionsLayout>
+
+export default SessionsPage