The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Rewrite the Auth components using react-query.
Ivan Vasilov1c95b0766cee
diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsxindex f9ab8236697..695e69e8d72 100644--- a/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx+++ b/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx@@ -1,13 +1,16 @@-import { observer } from 'mobx-react-lite'-import { useStore, useFlag } from 'hooks'-import { PROVIDERS_SCHEMAS, PROVIDER_SAML } from 'stores/authConfig/schema'+import { useParams } from 'common'import { FormHeader } from 'components/ui/Forms'import { HorizontalShimmerWithIcon } from 'components/ui/Shimmers'-import ProviderForm from './ProviderForm'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useFlag } from 'hooks'+import { observer } from 'mobx-react-lite'+import { PROVIDERS_SCHEMAS, PROVIDER_SAML } from 'stores/authConfig/schema'import { ProviderCollapsibleClasses } from './AuthProvidersForm.constants'+import ProviderForm from './ProviderForm'const AuthProvidersForm = () => {- const { authConfig } = useStore()+ const { ref: projectRef } = useParams()+ const { isFetched } = useAuthConfigQuery({ projectRef })const isSamlEnabled = useFlag('isSamlEnabled')const providers = isSamlEnabled? PROVIDERS_SCHEMAS@@ -21,7 +24,7 @@ const AuthProvidersForm = () => {/><div className="-space-y-px">- {!authConfig.isLoaded+ {!isFetched? providers.map((provider) => (<divkey={`provider_${provider.title}`}diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsxindex 72177f07f78..d5bd2fd542c 100644--- a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx+++ b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx@@ -5,7 +5,8 @@ import ReactMarkdown from 'react-markdown'import { Alert, Button, Collapsible, Form, IconCheck, IconChevronUp, Input } from 'ui'import { useParams } from 'common'-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'import { useCheckPermissions, useStore } from 'hooks'import { BASE_PATH } from 'lib/constants'@@ -19,36 +20,40 @@ export interface ProviderFormProps {const ProviderForm = ({ provider }: ProviderFormProps) => {const [open, setOpen] = useState(false)- const { authConfig, ui } = useStore()- const { project: selectedProject } = useProjectContext()- const { ref } = useParams()+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()+const doubleNegativeKeys = ['MAILER_AUTOCONFIRM', 'SMS_AUTOCONFIRM']const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')- const { data: customDomainData } = useCustomDomainsQuery({ projectRef: ref })+ const { data: customDomainData } = useCustomDomainsQuery({ projectRef })const generateInitialValues = () => {const initialValues: { [x: string]: string } = {}+ // the config is already loaded through the parent component+ if (!config) {+ return+ }Object.keys(provider.properties).forEach((key) => {// When the key is a 'double negative' key, we must reverse the boolean before adding it to the formconst isDoubleNegative = doubleNegativeKeys.includes(key)if (provider.title === 'SAML 2.0') {- initialValues[key] = authConfig.config[key] ?? false+ initialValues[key] = (config as any)[key] ?? false} else {- initialValues[key] = isDoubleNegative- ? !authConfig.config[key]- : authConfig.config[key] ?? ''+ initialValues[key] = isDoubleNegative ? !(config as any)[key] : (config as any)[key] ?? ''}})return initialValues}// [Joshen] Doing this check as SAML doesn't follow the same naming structure as the other provider options- const isActive =+ const isActive: boolean =provider.title === 'SAML 2.0'- ? authConfig.config['SAML_ENABLED'] || false- : authConfig.config[`EXTERNAL_${provider?.title?.toUpperCase()}_ENABLED`]+ ? (config && (config as any)['SAML_ENABLED']) ?? false+ : (config && (config as any)[`EXTERNAL_${provider?.title?.toUpperCase()}_ENABLED`]) ?? falseconst INITIAL_VALUES = generateInitialValues()const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {@@ -61,21 +66,26 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {}})- const { error } = await authConfig.update(payload)-- if (!error) {- resetForm({ values: { ...values }, initialValues: { ...values } })- setOpen(false)- ui.setNotification({ category: 'success', message: 'Successfully updated settings' })- } else {- ui.setNotification({- error,- category: 'error',- message: `Failed to update settings: ${error?.message}`,- })- }-- setSubmitting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: payload },+ {+ onError: (error) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to update settings: ${error?.message}`,+ })+ },+ onSuccess: () => {+ resetForm({ values: { ...values }, initialValues: { ...values } })+ setOpen(false)+ ui.setNotification({ category: 'success', message: 'Successfully updated settings' })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}return (@@ -159,7 +169,7 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {value={customDomainData?.customDomain?.status === 'active'? `https://${customDomainData.customDomain?.hostname}/auth/v1/callback`- : `https://${selectedProject?.ref}.supabase.co/auth/v1/callback`+ : `https://${projectRef}.supabase.co/auth/v1/callback`}descriptionText={<ReactMarkdown unwrapDisallowed disallowedElements={['p']}>diff --git a/studio/components/interfaces/Auth/AutoSchemaForm.tsx b/studio/components/interfaces/Auth/AutoSchemaForm.tsxindex 72722a74e46..92e66631322 100644--- a/studio/components/interfaces/Auth/AutoSchemaForm.tsx+++ b/studio/components/interfaces/Auth/AutoSchemaForm.tsx@@ -1,10 +1,10 @@-import { useEffect, useState } from 'react'+import { PermissionAction } from '@supabase/shared-types/out/constants'import { observer } from 'mobx-react-lite'+import { useEffect, useState } from 'react'+import { Button, Form, IconEye, IconEyeOff, Input, InputNumber, Radio, Toggle } from 'ui'import { boolean, number, object, string } from 'yup'-import { PermissionAction } from '@supabase/shared-types/out/constants'-import { Button, Form, Input, IconEye, IconEyeOff, InputNumber, Toggle, Radio } from 'ui'-import { useStore, useCheckPermissions } from 'hooks'+import { useParams } from 'common'import {FormActions,FormHeader,@@ -13,25 +13,30 @@ import {FormSectionContent,FormSectionLabel,} from 'components/ui/Forms'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'+import { useCheckPermissions, useStore } from 'hooks'const AutoSchemaForm = observer(() => {- const { authConfig, ui } = useStore()- const { isLoaded } = authConfig+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()const formId = 'auth-config-general-form'const [hidden, setHidden] = useState(true)const canUpdateConfig = useCheckPermissions(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 || '',- SECURITY_CAPTCHA_PROVIDER: authConfig.config.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',- MFA_MAX_ENROLLED_FACTORS: authConfig.config.MFA_MAX_ENROLLED_FACTORS || 10,+ DISABLE_SIGNUP: config?.DISABLE_SIGNUP,+ SITE_URL: config?.SITE_URL,+ JWT_EXP: config?.JWT_EXP,+ REFRESH_TOKEN_ROTATION_ENABLED: config?.REFRESH_TOKEN_ROTATION_ENABLED || false,+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: config?.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,+ SECURITY_CAPTCHA_ENABLED: config?.SECURITY_CAPTCHA_ENABLED || false,+ SECURITY_CAPTCHA_SECRET: config?.SECURITY_CAPTCHA_SECRET || '',+ SECURITY_CAPTCHA_PROVIDER: config?.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',+ MFA_MAX_ENROLLED_FACTORS: config?.MFA_MAX_ENROLLED_FACTORS || 10,}const schema = object({@@ -65,22 +70,27 @@ const AutoSchemaForm = observer(() => {payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUPsetSubmitting(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: ${error?.message}`,- })- }-- setSubmitting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: payload },+ {+ onError: (error) => {+ ui.setNotification({+ category: 'error',+ message: `Failed to update settings: ${error?.message}`,+ })+ },+ onSuccess: () => {+ ui.setNotification({+ category: 'success',+ message: `Successfully updated settings`,+ })+ resetForm({ values: values, initialValues: values })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}return (@@ -91,7 +101,7 @@ const AutoSchemaForm = observer(() => {// Form is reset once remote data is loaded in storeuseEffect(() => {resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })- }, [authConfig.isLoaded])+ }, [isLoaded])return (<>diff --git a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsxindex 4ab4bdf3300..fe168d7f496 100644--- a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx+++ b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx@@ -7,6 +7,10 @@ import { Form, Input } from 'ui'import CodeEditor from 'components/ui/CodeEditor'import { FormActions, FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'import InformationBox from 'components/ui/InformationBox'++import { useParams } from 'common'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'import { useCheckPermissions, useStore } from 'hooks'import { FormSchema } from 'types'@@ -15,11 +19,13 @@ interface TemplateEditorProps {}const TemplateEditor = ({ template }: TemplateEditorProps) => {- const { ui, authConfig } = useStore()+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()const [bodyValue, setBodyValue] = useState('')-- const { isLoaded } = authConfigconst { id, properties } = template+ const config = data as Record<string, string> | undefinedconst formId = `auth-config-email-templates-${id}`const INITIAL_VALUES: { [x: string]: string } = {}@@ -28,7 +34,7 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {useEffect(() => {if (isLoaded) {Object.keys(properties).forEach((key) => {- INITIAL_VALUES[key] = authConfig.config[key] ?? ''+ INITIAL_VALUES[key] = (config && config[key]) ?? ''})}}, [isLoaded])@@ -36,7 +42,7 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {const messageSlug = `MAILER_TEMPLATES_${id}_CONTENT`const messageProperty = properties[messageSlug]- const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {+ const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {const payload = { ...values }// Because the template content uses the code editor which is not a form component@@ -45,20 +51,24 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {if (messageProperty) payload[messageSlug] = bodyValuesetSubmitting(true)- const { error } = await authConfig.update(payload)-- if (!error) {- ui.setNotification({ category: 'success', message: 'Successfully updated settings' })- resetForm({- values: values,- initialValues: values,- })- setBodyValue(authConfig?.config?.[messageSlug])- } else {- ui.setNotification({ category: 'error', message: 'Failed to update settings' })- }-- setSubmitting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: payload },+ {+ onError: () => {+ ui.setNotification({ category: 'error', message: 'Failed to update settings' })+ },+ onSuccess: () => {+ ui.setNotification({ category: 'success', message: 'Successfully updated settings' })+ resetForm({+ values: values,+ initialValues: values,+ })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}return (@@ -73,10 +83,10 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {values: INITIAL_VALUES,initialValues: INITIAL_VALUES,})- setBodyValue(authConfig?.config?.[messageSlug])- }, [authConfig.isLoaded])+ setBodyValue((config && config[messageSlug]) ?? '')+ }, [isLoaded])- const message = authConfig?.config?.[messageSlug]+ const message = (config && config[messageSlug]) ?? ''const hasChanges =JSON.stringify(values) !== JSON.stringify(initialValues) || message !== bodyValue@@ -157,10 +167,10 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {<FormActionshandleReset={() => {resetForm({- values: authConfig.config,- initialValues: authConfig.config,+ values: config,+ initialValues: config,})- setBodyValue(authConfig?.config?.[messageSlug])+ setBodyValue((config && config[messageSlug]) ?? '')}}form={formId}isSubmitting={isSubmitting}diff --git a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsxindex 81bbb966fda..30e9f13ba10 100644--- a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx+++ b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx@@ -2,9 +2,10 @@ import { noop } from 'lodash'import { observer } from 'mobx-react-lite'import { Button, IconGlobe, IconTrash } from 'ui'+import { useParams } from 'common'import { HorizontalShimmerWithIcon } from 'components/ui/Shimmers'import { EmptyListState } from 'components/ui/States'-import { useStore } from 'hooks'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'import ValueContainer from './ValueContainer'interface RedirectUrlListProps {@@ -13,15 +14,14 @@ interface RedirectUrlListProps {}const RedirectUrlList = ({ canUpdate, onSelectUrlToDelete = noop }: RedirectUrlListProps) => {- const { authConfig } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })- const URI_ALLOW_LIST_ARRAY = authConfig.config.URI_ALLOW_LIST- ? authConfig.config.URI_ALLOW_LIST.split(',')- : []+ const URI_ALLOW_LIST_ARRAY = config?.URI_ALLOW_LIST ? config.URI_ALLOW_LIST.split(',') : []return (<div className="-space-y-px">- {!authConfig.isLoaded ? (+ {!isLoaded ? (<><ValueContainer><HorizontalShimmerWithIcon />diff --git a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsxindex 19ed2369767..95010a466f4 100644--- a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx+++ b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx@@ -1,20 +1,26 @@-import { useState } from 'react'-import { object, string } from 'yup'-import { observer } from 'mobx-react-lite'import * as Tooltip from '@radix-ui/react-tooltip'-import { Button, Form, Input, Modal } from 'ui'import { PermissionAction } from '@supabase/shared-types/out/constants'+import { observer } from 'mobx-react-lite'+import { useState } from 'react'+import { Button, Form, Input, Modal } from 'ui'+import { object, string } from 'yup'-import { useCheckPermissions, useStore } from 'hooks'+import { useParams } from 'common'import { FormHeader } from 'components/ui/Forms'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'+import { useCheckPermissions, useStore } from 'hooks'import { urlRegex } from '../Auth.constants'import RedirectUrlList from './RedirectUrlList'const RedirectUrls = () => {- const { authConfig, ui } = useStore()+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()- const URI_ALLOW_LIST_ARRAY = authConfig.config.URI_ALLOW_LIST- ? authConfig.config.URI_ALLOW_LIST.split(/\s*[,]+\s*/).filter((url: string) => url)+ const URI_ALLOW_LIST_ARRAY = config?.URI_ALLOW_LIST+ ? config.URI_ALLOW_LIST.split(/\s*[,]+\s*/).filter((url: string) => url): []const [open, setOpen] = useState(false)@@ -49,19 +55,25 @@ const RedirectUrls = () => {return}- const { error } = await authConfig.update({ URI_ALLOW_LIST: payloadString })- if (!error) {- setOpen(false)- ui.setNotification({ category: 'success', message: 'Successfully added URL' })- } else {- ui.setNotification({- error,- category: 'error',- message: `Failed to update URL: ${error?.message}`,- })- }-- setSubmitting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: { URI_ALLOW_LIST: payloadString } },+ {+ onError: (error) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to update URL: ${error?.message}`,+ })+ },+ onSuccess: () => {+ setOpen(false)+ ui.setNotification({ category: 'success', message: 'Successfully added URL' })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}const onConfirmDeleteUrl = async (url?: string) => {@@ -72,20 +84,25 @@ const RedirectUrls = () => {// Remove selectedUrl from array and updateconst payload = URI_ALLOW_LIST_ARRAY.filter((e: string) => e !== url)- const { error } = await authConfig.update({ URI_ALLOW_LIST: payload.toString() })-- if (!error) {- setSelectedUrlToDelete(undefined)- ui.setNotification({ category: 'success', message: 'Successfully removed URL' })- } else {- ui.setNotification({- error,- category: 'error',- message: `Failed to remove URL: ${error?.message}`,- })- }-- setIsDeleting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: { URI_ALLOW_LIST: payload.toString() } },+ {+ onError: (error) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to remove URL: ${error?.message}`,+ })+ },+ onSuccess: () => {+ setSelectedUrlToDelete(undefined)+ ui.setNotification({ category: 'success', message: 'Successfully removed URL' })+ },+ onSettled: () => {+ setIsDeleting(false)+ },+ }+ )}return (diff --git a/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx b/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsxindex b19659bb96c..2470fed6324 100644--- a/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx+++ b/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx@@ -4,6 +4,7 @@ import { useEffect } from 'react'import { Form, Input } from 'ui'import { boolean, number, object, string } from 'yup'+import { useParams } from 'common'import {FormActions,FormHeader,@@ -11,24 +12,28 @@ import {FormSection,FormSectionContent,} from 'components/ui/Forms'-import { useCheckPermissions, useSelectedProject, useStore } from 'hooks'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'+import { useCheckPermissions, useStore } from 'hooks'const SiteUrl = observer(() => {- const { authConfig, ui } = useStore()- const { isLoaded } = authConfig+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()const formId = 'auth-config-general-form'const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')const INITIAL_VALUES = {- DISABLE_SIGNUP: !authConfig.config.DISABLE_SIGNUP,- JWT_EXP: authConfig.config.JWT_EXP,- SITE_URL: authConfig.config.SITE_URL,- 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_PROVIDER: authConfig.config.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',- SECURITY_CAPTCHA_SECRET: authConfig.config.SECURITY_CAPTCHA_SECRET || '',+ DISABLE_SIGNUP: config?.DISABLE_SIGNUP,+ JWT_EXP: config?.JWT_EXP,+ SITE_URL: config?.SITE_URL,+ REFRESH_TOKEN_ROTATION_ENABLED: config?.REFRESH_TOKEN_ROTATION_ENABLED || false,+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: config?.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,+ SECURITY_CAPTCHA_ENABLED: config?.SECURITY_CAPTCHA_ENABLED || false,+ SECURITY_CAPTCHA_PROVIDER: config?.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',+ SECURITY_CAPTCHA_SECRET: config?.SECURITY_CAPTCHA_SECRET || '',}const schema = object({@@ -48,27 +53,32 @@ const SiteUrl = observer(() => {}),})- const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {+ const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {const payload = { ...values }payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUPsetSubmitting(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)+ updateAuthConfig(+ { projectRef: projectRef!, config: payload },+ {+ onError: () => {+ ui.setNotification({+ category: 'error',+ message: `Failed to update settings`,+ })+ },+ onSuccess: () => {+ ui.setNotification({+ category: 'success',+ message: `Successfully updated settings`,+ })+ resetForm({ values: values, initialValues: values })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}return (@@ -79,7 +89,7 @@ const SiteUrl = observer(() => {// Form is reset once remote data is loaded in storeuseEffect(() => {resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })- }, [authConfig.isLoaded])+ }, [isLoaded])return (<>diff --git a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsxindex 4479917bd5c..3bd9dffefd0 100644--- a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx+++ b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx@@ -17,6 +17,7 @@ import {} from 'ui'import { number, object, string } from 'yup'+import { useParams } from 'common'import {FormActions,FormHeader,@@ -25,20 +26,24 @@ import {FormSectionContent,FormSectionLabel,} from 'components/ui/Forms'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'import { useCheckPermissions, useStore } from 'hooks'import { urlRegex } from './../Auth.constants'import { defaultDisabledSmtpFormValues } from './SmtpForm.constants'import { generateFormValues, isSmtpEnabled } from './SmtpForm.utils'const SmtpForm = () => {- const { authConfig, ui } = useStore()- const { config, isLoaded } = authConfig+ const { ui } = useStore()+ const { ref: projectRef } = useParams()+ const { data: config, isLoading, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })+ const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()const [enableSmtp, setEnableSmtp] = useState(false)const [hidden, setHidden] = useState(true)const formId = 'auth-config-smtp-form'- const initialValues = generateFormValues(authConfig.config)+ const initialValues = generateFormValues(config)const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')useEffect(() => {@@ -110,7 +115,7 @@ const SmtpForm = () => {}),})- const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {+ const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {const payload = enableSmtp ? values : defaultDisabledSmtpFormValues// Format payload: Remove redundant value + convert port to string@@ -118,18 +123,23 @@ const SmtpForm = () => {payload.SMTP_PORT = payload.SMTP_PORT ? payload.SMTP_PORT.toString() : payload.SMTP_PORTsetSubmitting(true)- const { error } = await authConfig.update(payload)-- if (!error) {- setHidden(true)- const updatedFormValues = generateFormValues(payload)- resetForm({ values: updatedFormValues, initialValues: updatedFormValues })- ui.setNotification({ category: 'success', message: 'Successfully updated settings' })- } else {- ui.setNotification({ category: 'error', message: 'Failed to update settings', error })- }-- setSubmitting(false)+ updateAuthConfig(+ { projectRef: projectRef!, config: payload },+ {+ onError: (error) => {+ ui.setNotification({ category: 'error', message: 'Failed to update settings', error })+ },+ onSuccess: () => {+ setHidden(true)+ const updatedFormValues = generateFormValues(payload)+ resetForm({ values: updatedFormValues, initialValues: updatedFormValues })+ ui.setNotification({ category: 'success', message: 'Successfully updated settings' })+ },+ onSettled: () => {+ setSubmitting(false)+ },+ }+ )}return (@@ -178,7 +188,7 @@ const SmtpForm = () => {}><FormSection>- <FormSectionContent loading={!isLoaded}>+ <FormSectionContent loading={isLoading}><Togglename="ENABLE_SMTP"size="small"@@ -217,7 +227,7 @@ const SmtpForm = () => {<ahref="https://supabase.com/docs/guides/platform/going-into-prod#auth-rate-limits"className="underline"- target="_blank"+ target="_blank">documentation</a>{' '}@@ -233,7 +243,7 @@ const SmtpForm = () => {header={<FormSectionLabel>Sender details</FormSectionLabel>}disabled={!enableSmtp}>- <FormSectionContent loading={!isLoaded}>+ <FormSectionContent loading={isLoading}><Inputname="SMTP_ADMIN_EMAIL"id="SMTP_ADMIN_EMAIL"@@ -265,7 +275,7 @@ const SmtpForm = () => {</FormSectionLabel>}>- <FormSectionContent loading={!isLoaded}>+ <FormSectionContent loading={isLoading}><Inputname="SMTP_HOST"placeholder="your.smtp.host.com"diff --git a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.tsindex 15f20631987..ad2539209d4 100644--- a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts+++ b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts@@ -1,4 +1,6 @@-import { AuthConfig } from '../Auth.types'+import { components } from 'data/api'++type AuthConfig = components['schemas']['GoTrueConfig']interface AuthConfigForm extends AuthConfig {ENABLE_SMTP: boolean@@ -24,7 +26,7 @@ export const generateFormValues = (config?: Partial<AuthConfig>): Partial<AuthCoSMTP_USER: config?.SMTP_USER ?? '',SMTP_HOST: config?.SMTP_HOST ?? '',SMTP_PASS: config?.SMTP_PASS ?? '',- SMTP_PORT: config?.SMTP_PORT ?? 465,+ SMTP_PORT: config?.SMTP_PORT ?? '465',SMTP_MAX_FREQUENCY: config?.SMTP_MAX_FREQUENCY ?? 60,RATE_LIMIT_EMAIL_SENT: config?.RATE_LIMIT_EMAIL_SENT ?? 30,}