import { useEffect, useState } from 'react' import { observer } from 'mobx-react-lite' import { boolean, number, object, string } from 'yup' import { PermissionAction } from '@supabase/shared-types/out/constants' import { Button, Form, Input, IconEye, IconEyeOff, InputNumber, Toggle } from 'ui' import { useStore, checkPermissions, useFlag } from 'hooks' import { FormActions, FormHeader, FormPanel, FormSection, FormSectionContent, FormSectionLabel, } from 'components/ui/Forms' const AutoSchemaForm = observer(() => { const { authConfig, ui } = useStore() const { isLoaded } = authConfig const formId = 'auth-config-general-form' const [hidden, setHidden] = useState(true) const showMfaSso = useFlag('mfaSso') const canUpdateConfig = checkPermissions(PermissionAction.UPDATE, 'custom_config_gotrue') const INITIAL_VALUES = { DISABLE_SIGNUP: !authConfig.config.DISABLE_SIGNUP, SITE_URL: authConfig.config.SITE_URL, JWT_EXP: authConfig.config.JWT_EXP, REFRESH_TOKEN_ROTATION_ENABLED: authConfig.config.REFRESH_TOKEN_ROTATION_ENABLED || false, SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: authConfig.config.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL, SECURITY_CAPTCHA_ENABLED: authConfig.config.SECURITY_CAPTCHA_ENABLED || false, SECURITY_CAPTCHA_SECRET: authConfig.config.SECURITY_CAPTCHA_SECRET || '', MAX_ENROLLED_FACTORS: authConfig.config.MAX_ENROLLED_FACTORS, } const schema = object({ DISABLE_SIGNUP: boolean().required(), SITE_URL: string().required('Must have a Site URL'), JWT_EXP: number() .max(604800, 'Must be less than 604800') .required('Must have a JWT expiry value'), 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'), SECURITY_CAPTCHA_ENABLED: boolean().required(), SECURITY_CAPTCHA_SECRET: string().when('SECURITY_CAPTCHA_ENABLED', { is: true, then: string().required('Must have a hCaptcha secret'), }), MAX_ENROLLED_FACTORS: number() .min(0, 'Must be be a value more than 0') .max(30, 'Must be a value less than 30'), }) const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => { const payload = { ...values } payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUP payload.SECURITY_CAPTCHA_PROVIDER = 'hcaptcha' setSubmitting(true) const { error } = await authConfig.update(payload) if (!error) { ui.setNotification({ category: 'success', message: `Successfully updated settings`, }) resetForm({ values: values, initialValues: values }) } else { ui.setNotification({ category: 'error', message: `Failed to update settings`, }) } setSubmitting(false) } return (
) }) export default AutoSchemaForm