The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix error handling in auth settings forms
Joshen Lim345f1833785c
diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsxindex 41a5c52f44a..b34fcb250f7 100644--- a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx+++ b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx@@ -31,28 +31,30 @@ const ProviderForm: FC<Props> = ({ provider }) => {const INITIAL_VALUES = generateInitialValues()const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {- try {- const payload = { ...values }+ const payload = { ...values }- // When the key is a 'double negative' key, we must reverse the boolean before the payload can be sent- Object.keys(values).map((x: string) => {- if (doubleNegativeKeys.includes(x)) {- payload[x] = !values[x]- }- })+ // When the key is a 'double negative' key, we must reverse the boolean before the payload can be sent+ Object.keys(values).map((x: string) => {+ if (doubleNegativeKeys.includes(x)) {+ payload[x] = !values[x]+ }+ })- await authConfig.update(payload)+ const { error } = await authConfig.update(payload)++ if (!error) {resetForm({ values: payload, initialValues: payload })- setSubmitting(false)setOpen(false)ui.setNotification({ category: 'success', message: 'Successfully updated settings' })- } catch (error: any) {+ } else {ui.setNotification({error,category: 'error',message: `Failed to update settings: ${error?.message}`,})}++ setSubmitting(false)}return (diff --git a/studio/components/interfaces/Auth/AutoSchemaForm.tsx b/studio/components/interfaces/Auth/AutoSchemaForm.tsxindex 614f22634f8..90a3456a477 100644--- a/studio/components/interfaces/Auth/AutoSchemaForm.tsx+++ b/studio/components/interfaces/Auth/AutoSchemaForm.tsx@@ -45,33 +45,32 @@ const AutoSchemaForm = observer(() => {}),})+ 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 (- <Form- id={formId}- initialValues={INITIAL_VALUES}- onSubmit={async (values: any, { setSubmitting, resetForm }: any) => {- const payload = { ...values }- payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUP- payload.SECURITY_CAPTCHA_PROVIDER = 'hcaptcha'- try {- setSubmitting(true)- await authConfig.update(payload)- setSubmitting(false)- ui.setNotification({- category: 'success',- message: `Successfully updated settings`,- })- resetForm({ values: values, initialValues: values })- } catch (error) {- ui.setNotification({- category: 'error',- message: `Failed to update settings`,- })- setSubmitting(false)- }- }}- validationSchema={schema}- >+ <Form id={formId} initialValues={INITIAL_VALUES} onSubmit={onSubmit} validationSchema={schema}>{({ isSubmitting, handleReset, resetForm, values, initialValues }: any) => {const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)diff --git a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsxindex b965126c551..b47625733ea 100644--- a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx+++ b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx@@ -42,20 +42,21 @@ const TemplateEditor: FC<Props> = ({ template }) => {delete payload[messageSlug]if (messageProperty) payload[messageSlug] = bodyValue- try {- setSubmitting(true)- await authConfig.update(payload)+ setSubmitting(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])- } catch (error) {+ } else {ui.setNotification({ category: 'error', message: 'Failed to update settings' })- } finally {- setSubmitting(false)}++ setSubmitting(false)}return (diff --git a/studio/components/interfaces/Auth/RedirectDomains/RedirectDomains.tsx b/studio/components/interfaces/Auth/RedirectDomains/RedirectDomains.tsxindex 621fd3f2241..60f4d9d15f6 100644--- a/studio/components/interfaces/Auth/RedirectDomains/RedirectDomains.tsx+++ b/studio/components/interfaces/Auth/RedirectDomains/RedirectDomains.tsx@@ -25,43 +25,46 @@ const RedirectDomains = () => {const onAddNewDomain = async (values: any, { setSubmitting }: any) => {setSubmitting(true)- try {- const payload = URI_ALLOW_LIST_ARRAY- payload.push(values.domain)- // convert payload to comma seperated string and update- await authConfig.update({ URI_ALLOW_LIST: payload.toString() })- setSubmitting(false)+ const payload = URI_ALLOW_LIST_ARRAY+ payload.push(values.domain)++ const { error } = await authConfig.update({ URI_ALLOW_LIST: payload.toString() })+ if (!error) {setOpen(false)ui.setNotification({ category: 'success', message: 'Successfully added domain' })- } catch (error: any) {- setSubmitting(false)+ } else {ui.setNotification({error,category: 'error',message: `Failed to update domain: ${error?.message}`,})}++ setSubmitting(false)}const onConfirmDeleteDomain = async (domain?: string) => {if (!domain) returnsetIsDeleting(true)- try {- // Remove selectedDomain from array and update- const payload = URI_ALLOW_LIST_ARRAY.filter((e: string) => e !== domain)- await authConfig.update({ URI_ALLOW_LIST: payload.toString() })- setIsDeleting(false)++ // Remove selectedDomain from array and update+ const payload = URI_ALLOW_LIST_ARRAY.filter((e: string) => e !== domain)++ const { error } = await authConfig.update({ URI_ALLOW_LIST: payload.toString() })++ if (!error) {setSelectedDomainToDelete(undefined)ui.setNotification({ category: 'success', message: 'Successfully removed domain' })- } catch (error: any) {- setIsDeleting(false)+ } else {ui.setNotification({error,category: 'error',message: `Failed to remove domain: ${error?.message}`,})}++ setIsDeleting(false)}return (diff --git a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsxindex 14bc3907cdc..b1acce0d3e2 100644--- a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx+++ b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx@@ -102,19 +102,19 @@ const SmtpForm = () => {delete payload.ENABLE_SMTPpayload.SMTP_PORT = payload.SMTP_PORT ? payload.SMTP_PORT.toString() : payload.SMTP_PORT- try {- setSubmitting(true)- await authConfig.update(payload)- ui.setNotification({ category: 'success', message: 'Successfully updated settings' })+ setSubmitting(true)+ const { error } = await authConfig.update(payload)+ if (!error) {setHidden(true)const updatedFormValues = generateFormValues(payload)resetForm({ values: updatedFormValues, initialValues: updatedFormValues })- } catch (error) {+ ui.setNotification({ category: 'success', message: 'Successfully updated settings' })+ } else {ui.setNotification({ category: 'error', message: 'Failed to update settings', error })- } finally {- setSubmitting(false)}++ setSubmitting(false)}return (