Skip to content

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

Fix all remarks from Joshens review.

Ivan Vasilov339bb538b633
diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx
index 695e69e8d72..bce8a499cea 100644
--- a/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx
+++ b/studio/components/interfaces/Auth/AuthProvidersForm/AuthProvidersForm.tsx
@@ -5,12 +5,20 @@ 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 { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, IconAlertCircle } from 'ui'
import { ProviderCollapsibleClasses } from './AuthProvidersForm.constants'
import ProviderForm from './ProviderForm'
const AuthProvidersForm = () => {
const { ref: projectRef } = useParams()
- const { isFetched } = useAuthConfigQuery({ projectRef })
+ const {
+ isLoading,
+ error: authConfigError,
+ isError,
+ data: authConfig,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+
const isSamlEnabled = useFlag('isSamlEnabled')
const providers = isSamlEnabled
? PROVIDERS_SCHEMAS
@@ -24,19 +32,32 @@ const AuthProvidersForm = () => {
/>
<div className="-space-y-px">
- {!isFetched
- ? providers.map((provider) => (
- <div
+ {isLoading &&
+ providers.map((provider) => (
+ <div
+ key={`provider_${provider.title}`}
+ className={[...ProviderCollapsibleClasses, 'px-6 py-3'].join(' ')}
+ >
+ <HorizontalShimmerWithIcon />
+ </div>
+ ))}
+ {isError && (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ {isSuccess &&
+ providers.map((provider) => {
+ return (
+ <ProviderForm
key={`provider_${provider.title}`}
- className={[...ProviderCollapsibleClasses, 'px-6 py-3'].join(' ')}
- >
- <HorizontalShimmerWithIcon />
- </div>
- ))
- : providers.map((provider) => {
- // @ts-expect-error: Fix type to be dynamic
- return <ProviderForm key={`provider_${provider.title}`} provider={provider} />
- })}
+ config={authConfig}
+ provider={provider as any}
+ />
+ )
+ })}
</div>
</div>
)
diff --git a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx
index d5bd2fd542c..6d6d3a565c0 100644
--- a/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx
+++ b/studio/components/interfaces/Auth/AuthProvidersForm/ProviderForm.tsx
@@ -5,7 +5,7 @@ import ReactMarkdown from 'react-markdown'
import { Alert, Button, Collapsible, Form, IconCheck, IconChevronUp, Input } from 'ui'
import { useParams } from 'common'
-import { useAuthConfigQuery } from 'data/auth/auth-config-query'
+import { components } from 'data/api'
import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'
import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useCheckPermissions, useStore } from 'hooks'
@@ -15,16 +15,15 @@ import { Provider } from './AuthProvidersForm.types'
import FormField from './FormField'
export interface ProviderFormProps {
+ config: components['schemas']['GetGoTrueConfigResponse']
provider: Provider
}
-const ProviderForm = ({ provider }: ProviderFormProps) => {
+const ProviderForm = ({ config, provider }: ProviderFormProps) => {
const [open, setOpen] = useState(false)
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data: config } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
-
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
const doubleNegativeKeys = ['MAILER_AUTOCONFIRM', 'SMS_AUTOCONFIRM']
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
@@ -33,9 +32,6 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
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 form
const isDoubleNegative = doubleNegativeKeys.includes(key)
@@ -56,7 +52,7 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
: (config && (config as any)[`EXTERNAL_${provider?.title?.toUpperCase()}_ENABLED`]) ?? false
const INITIAL_VALUES = generateInitialValues()
- const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {
+ const onSubmit = (values: any, { resetForm }: any) => {
const payload = { ...values }
// When the key is a 'double negative' key, we must reverse the boolean before the payload can be sent
@@ -81,9 +77,6 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
setOpen(false)
ui.setNotification({ category: 'success', message: 'Successfully updated settings' })
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
@@ -134,7 +127,7 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
validationSchema={provider.validationSchema}
onSubmit={onSubmit}
>
- {({ isSubmitting, handleReset, initialValues, values }: any) => {
+ {({ handleReset, initialValues, values }: any) => {
const noChanges = JSON.stringify(initialValues) === JSON.stringify(values)
return (
<Collapsible.Content>
@@ -187,7 +180,7 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
handleReset()
setOpen(false)
}}
- disabled={isSubmitting}
+ disabled={isUpdatingConfig}
>
Cancel
</Button>
@@ -195,8 +188,8 @@ const ProviderForm = ({ provider }: ProviderFormProps) => {
<Tooltip.Trigger type="button">
<Button
htmlType="submit"
- loading={isSubmitting}
- disabled={isSubmitting || !canUpdateConfig || noChanges}
+ loading={isUpdatingConfig}
+ disabled={isUpdatingConfig || !canUpdateConfig || noChanges}
>
Save
</Button>
diff --git a/studio/components/interfaces/Auth/AutoSchemaForm.tsx b/studio/components/interfaces/Auth/AutoSchemaForm.tsx
index 92e66631322..0c48238e8ad 100644
--- a/studio/components/interfaces/Auth/AutoSchemaForm.tsx
+++ b/studio/components/interfaces/Auth/AutoSchemaForm.tsx
@@ -1,7 +1,20 @@
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 {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ Form,
+ IconAlertCircle,
+ IconEye,
+ IconEyeOff,
+ Input,
+ InputNumber,
+ Radio,
+ Toggle,
+} from 'ui'
import { boolean, number, object, string } from 'yup'
import { useParams } from 'common'
@@ -20,23 +33,29 @@ import { useCheckPermissions, useStore } from 'hooks'
const AutoSchemaForm = observer(() => {
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
+ const {
+ data: authConfig,
+ error: authConfigError,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = 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: 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,
+ DISABLE_SIGNUP: !authConfig?.DISABLE_SIGNUP,
+ SITE_URL: authConfig?.SITE_URL,
+ JWT_EXP: authConfig?.JWT_EXP,
+ REFRESH_TOKEN_ROTATION_ENABLED: authConfig?.REFRESH_TOKEN_ROTATION_ENABLED || false,
+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: authConfig?.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,
+ SECURITY_CAPTCHA_ENABLED: authConfig?.SECURITY_CAPTCHA_ENABLED || false,
+ SECURITY_CAPTCHA_SECRET: authConfig?.SECURITY_CAPTCHA_SECRET || '',
+ SECURITY_CAPTCHA_PROVIDER: authConfig?.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',
+ MFA_MAX_ENROLLED_FACTORS: authConfig?.MFA_MAX_ENROLLED_FACTORS || 10,
}
const schema = object({
@@ -65,11 +84,10 @@ const AutoSchemaForm = observer(() => {
.max(30, 'Must be a value less than 30'),
})
- const onSubmit = async (values: any, { setSubmitting, resetForm }: any) => {
+ const onSubmit = (values: any, { resetForm }: any) => {
const payload = { ...values }
payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUP
- setSubmitting(true)
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
@@ -86,22 +104,29 @@ const AutoSchemaForm = observer(() => {
})
resetForm({ values: values, initialValues: values })
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
+ if (isError) {
+ return (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )
+ }
+
return (
<Form id={formId} initialValues={INITIAL_VALUES} onSubmit={onSubmit} validationSchema={schema}>
- {({ isSubmitting, handleReset, resetForm, values, initialValues }: any) => {
+ {({ handleReset, resetForm, values, initialValues }: any) => {
const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
// Form is reset once remote data is loaded in store
useEffect(() => {
- resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })
- }, [isLoaded])
+ if (isSuccess) resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })
+ }, [isSuccess])
return (
<>
@@ -115,7 +140,7 @@ const AutoSchemaForm = observer(() => {
<div className="flex py-4 px-8">
<FormActions
form={formId}
- isSubmitting={isSubmitting}
+ isSubmitting={isUpdatingConfig}
hasChanges={hasChanges}
handleReset={handleReset}
disabled={!canUpdateConfig}
@@ -129,7 +154,7 @@ const AutoSchemaForm = observer(() => {
}
>
<FormSection header={<FormSectionLabel>User Signups</FormSectionLabel>}>
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={isLoading}>
<Toggle
id="DISABLE_SIGNUP"
size="small"
@@ -142,7 +167,7 @@ const AutoSchemaForm = observer(() => {
</FormSection>
<div className="border-t border-scale-400"></div>
<FormSection header={<FormSectionLabel>User Sessions</FormSectionLabel>}>
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={isLoading}>
{/* Permitted redirects for anything on that domain */}
{/* Check with @kangming about this */}
<InputNumber
@@ -156,7 +181,7 @@ const AutoSchemaForm = observer(() => {
</FormSectionContent>
</FormSection>
<FormSection header={<FormSectionLabel>Security and Protection</FormSectionLabel>}>
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={isLoading}>
<Toggle
id="SECURITY_CAPTCHA_ENABLED"
size="small"
@@ -223,7 +248,7 @@ const AutoSchemaForm = observer(() => {
<FormSection
header={<FormSectionLabel>Multi Factor Authentication (MFA)</FormSectionLabel>}
>
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={isLoading}>
<InputNumber
id="MFA_MAX_ENROLLED_FACTORS"
size="small"
diff --git a/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx b/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
index 3d9e5011415..d142bf83001 100644
--- a/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
+++ b/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
@@ -1,11 +1,30 @@
-import { Button, IconExternalLink, Tabs } from 'ui'
-import { observer } from 'mobx-react-lite'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ IconAlertCircle,
+ IconExternalLink,
+ Tabs,
+} from 'ui'
-import { TEMPLATES_SCHEMAS } from 'stores/authConfig/schema'
+import { useParams } from 'common'
import { FormHeader, FormPanel } from 'components/ui/Forms'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useAuthConfigQuery } from 'data/auth/auth-config-query'
+import { TEMPLATES_SCHEMAS } from 'stores/authConfig/schema'
import TemplateEditor from './TemplateEditor'
-const EmailTemplates = observer(() => {
+const EmailTemplates = () => {
+ const { ref: projectRef } = useParams()
+ const {
+ data: authConfig,
+ error: authConfigError,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+
return (
<div>
<div className="flex justify-between items-center">
@@ -25,26 +44,40 @@ const EmailTemplates = observer(() => {
</Button>
</div>
</div>
- <FormPanel>
- <Tabs
- scrollable
- size="small"
- type="underlined"
- listClassNames="px-8 pt-4"
- defaultActiveId={TEMPLATES_SCHEMAS[0].title.trim().replace(/\s+/g, '-')}
- >
- {TEMPLATES_SCHEMAS.map((template) => {
- const panelId = template.title.trim().replace(/\s+/g, '-')
- return (
- <Tabs.Panel id={panelId} label={template.title} key={panelId}>
- <TemplateEditor key={template.title} template={template} />
- </Tabs.Panel>
- )
- })}
- </Tabs>
- </FormPanel>
+ {isError && (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ {isLoading && <GenericSkeletonLoader />}
+ {isSuccess && (
+ <FormPanel>
+ <Tabs
+ scrollable
+ size="small"
+ type="underlined"
+ listClassNames="px-8 pt-4"
+ defaultActiveId={TEMPLATES_SCHEMAS[0].title.trim().replace(/\s+/g, '-')}
+ >
+ {TEMPLATES_SCHEMAS.map((template) => {
+ const panelId = template.title.trim().replace(/\s+/g, '-')
+ return (
+ <Tabs.Panel id={panelId} label={template.title} key={panelId}>
+ <TemplateEditor
+ key={template.title}
+ template={template}
+ authConfig={authConfig as any}
+ />
+ </Tabs.Panel>
+ )
+ })}
+ </Tabs>
+ </FormPanel>
+ )}
</div>
)
-})
+}
export default EmailTemplates
diff --git a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
index fe168d7f496..b65d3edbad2 100644
--- a/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
+++ b/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
@@ -1,6 +1,6 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { observer } from 'mobx-react-lite'
-import { useEffect, useState } from 'react'
+import { useMemo, useState } from 'react'
import ReactMarkdown from 'react-markdown'
import { Form, Input } from 'ui'
@@ -9,40 +9,37 @@ import { FormActions, FormSection, FormSectionContent, FormSectionLabel } from '
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'
interface TemplateEditorProps {
template: FormSchema
+ authConfig: Record<string, string>
}
-const TemplateEditor = ({ template }: TemplateEditorProps) => {
+const TemplateEditor = ({ template, authConfig }: TemplateEditorProps) => {
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
- const [bodyValue, setBodyValue] = useState('')
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
+
const { id, properties } = template
- const config = data as Record<string, string> | undefined
const formId = `auth-config-email-templates-${id}`
- const INITIAL_VALUES: { [x: string]: string } = {}
+ const INITIAL_VALUES = useMemo(() => {
+ const result: { [x: string]: string } = {}
+ Object.keys(properties).forEach((key) => {
+ result[key] = (authConfig && authConfig[key]) ?? ''
+ })
+ return result
+ }, [authConfig, properties])
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
- useEffect(() => {
- if (isLoaded) {
- Object.keys(properties).forEach((key) => {
- INITIAL_VALUES[key] = (config && config[key]) ?? ''
- })
- }
- }, [isLoaded])
-
const messageSlug = `MAILER_TEMPLATES_${id}_CONTENT`
const messageProperty = properties[messageSlug]
+ const [bodyValue, setBodyValue] = useState((authConfig && authConfig[messageSlug]) ?? '')
- const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {
+ const onSubmit = (values: any, { resetForm }: any) => {
const payload = { ...values }
// Because the template content uses the code editor which is not a form component
@@ -50,7 +47,6 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
delete payload[messageSlug]
if (messageProperty) payload[messageSlug] = bodyValue
- setSubmitting(true)
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
@@ -64,36 +60,21 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
initialValues: values,
})
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
return (
<Form id={formId} className="!border-t-0" initialValues={INITIAL_VALUES} onSubmit={onSubmit}>
- {({ isSubmitting, resetForm, values, initialValues }: any) => {
- // [Alaister] although this "technically" is breaking the rules of React hooks
- // it won't error because the hooks are always rendered in the same order
- // eslint-disable-next-line react-hooks/rules-of-hooks
- useEffect(() => {
- // Form is reset once remote data is loaded in store
- resetForm({
- values: INITIAL_VALUES,
- initialValues: INITIAL_VALUES,
- })
- setBodyValue((config && config[messageSlug]) ?? '')
- }, [isLoaded])
-
- const message = (config && config[messageSlug]) ?? ''
+ {({ resetForm, values, initialValues }: any) => {
+ const message = (authConfig && authConfig[messageSlug]) ?? ''
const hasChanges =
JSON.stringify(values) !== JSON.stringify(initialValues) || message !== bodyValue
return (
<>
<FormSection className="!border-t-0 pb-8 pt-4">
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={false}>
{Object.keys(properties).map((x: string) => {
const property = properties[x]
if (property.type === 'string') {
@@ -131,7 +112,7 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
</FormSectionContent>
</FormSection>
<FormSection className="!mt-0 grid-cols-12 !border-t-0 !pt-0">
- <FormSectionContent fullWidth loading={!isLoaded}>
+ <FormSectionContent fullWidth loading={false}>
{messageProperty && (
<>
<div className="space-y-3">
@@ -152,7 +133,6 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
<div className="relative h-96">
<CodeEditor
id="code-id"
- loading={!isLoaded}
language="html"
isReadOnly={!canUpdateConfig}
className="!mb-0 h-96 overflow-hidden rounded border"
@@ -167,13 +147,13 @@ const TemplateEditor = ({ template }: TemplateEditorProps) => {
<FormActions
handleReset={() => {
resetForm({
- values: config,
- initialValues: config,
+ values: authConfig,
+ initialValues: authConfig,
})
- setBodyValue((config && config[messageSlug]) ?? '')
+ setBodyValue((authConfig && authConfig[messageSlug]) ?? '')
}}
form={formId}
- isSubmitting={isSubmitting}
+ isSubmitting={isUpdatingConfig}
hasChanges={hasChanges}
disabled={!canUpdateConfig}
helper={
diff --git a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx
index 30e9f13ba10..191ac4de0f7 100644
--- a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx
+++ b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrlList.tsx
@@ -1,37 +1,24 @@
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 { useAuthConfigQuery } from 'data/auth/auth-config-query'
import ValueContainer from './ValueContainer'
interface RedirectUrlListProps {
+ URI_ALLOW_LIST_ARRAY: string[]
canUpdate: boolean
onSelectUrlToDelete: (url: string) => void
}
-const RedirectUrlList = ({ canUpdate, onSelectUrlToDelete = noop }: RedirectUrlListProps) => {
- const { ref: projectRef } = useParams()
- const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })
-
- const URI_ALLOW_LIST_ARRAY = config?.URI_ALLOW_LIST ? config.URI_ALLOW_LIST.split(',') : []
-
+const RedirectUrlList = ({
+ URI_ALLOW_LIST_ARRAY,
+ canUpdate,
+ onSelectUrlToDelete = noop,
+}: RedirectUrlListProps) => {
return (
<div className="-space-y-px">
- {!isLoaded ? (
- <>
- <ValueContainer>
- <HorizontalShimmerWithIcon />
- </ValueContainer>
- <ValueContainer>
- <HorizontalShimmerWithIcon />
- </ValueContainer>
- </>
- ) : URI_ALLOW_LIST_ARRAY.length > 0 ? (
- URI_ALLOW_LIST_ARRAY.map((url: string) => {
+ {URI_ALLOW_LIST_ARRAY.length > 0 ? (
+ URI_ALLOW_LIST_ARRAY.map((url) => {
return (
<ValueContainer key={url}>
<div className="flex items-center gap-4 font-mono">
@@ -69,4 +56,4 @@ const RedirectUrlList = ({ canUpdate, onSelectUrlToDelete = noop }: RedirectUrlL
)
}
-export default observer(RedirectUrlList)
+export default RedirectUrlList
diff --git a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx
index 95010a466f4..495fb5d6326 100644
--- a/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx
+++ b/studio/components/interfaces/Auth/RedirectUrls/RedirectUrls.tsx
@@ -1,30 +1,48 @@
import * as Tooltip from '@radix-ui/react-tooltip'
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 { useMemo, useState } from 'react'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ Form,
+ IconAlertCircle,
+ Input,
+ Modal,
+} from 'ui'
import { object, string } from 'yup'
import { useParams } from 'common'
import { FormHeader } from 'components/ui/Forms'
+import { HorizontalShimmerWithIcon } from 'components/ui/Shimmers'
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'
+import ValueContainer from './ValueContainer'
const RedirectUrls = () => {
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data: config } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
+ const {
+ data: authConfig,
+ error: authConfigError,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
- const URI_ALLOW_LIST_ARRAY = config?.URI_ALLOW_LIST
- ? config.URI_ALLOW_LIST.split(/\s*[,]+\s*/).filter((url: string) => url)
- : []
+ const URI_ALLOW_LIST_ARRAY = useMemo(() => {
+ return authConfig?.URI_ALLOW_LIST
+ ? authConfig.URI_ALLOW_LIST.split(/\s*[,]+\s*/).filter((url: string) => url)
+ : []
+ }, [authConfig?.URI_ALLOW_LIST])
const [open, setOpen] = useState(false)
- const [isDeleting, setIsDeleting] = useState(false)
const [selectedUrlToDelete, setSelectedUrlToDelete] = useState<string>()
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
@@ -33,12 +51,11 @@ const RedirectUrls = () => {
url: string().matches(urlRegex, 'URL is not valid').required(),
})
- const onAddNewUrl = async (values: any, { setSubmitting }: any) => {
+ const onAddNewUrl = async (values: any) => {
if (!values.url) {
return
}
- setSubmitting(true)
const payload = URI_ALLOW_LIST_ARRAY
// remove any trailing commas
payload.push(values.url.replace(/,\s*$/, ''))
@@ -50,8 +67,6 @@ const RedirectUrls = () => {
message: 'Too many redirect URLs, please remove some or try to use wildcards',
category: 'error',
})
-
- setSubmitting(false)
return
}
@@ -69,9 +84,6 @@ const RedirectUrls = () => {
setOpen(false)
ui.setNotification({ category: 'success', message: 'Successfully added URL' })
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
@@ -79,8 +91,6 @@ const RedirectUrls = () => {
const onConfirmDeleteUrl = async (url?: string) => {
if (!url) return
- setIsDeleting(true)
-
// Remove selectedUrl from array and update
const payload = URI_ALLOW_LIST_ARRAY.filter((e: string) => e !== url)
@@ -98,9 +108,6 @@ const RedirectUrls = () => {
setSelectedUrlToDelete(undefined)
ui.setNotification({ category: 'success', message: 'Successfully removed URL' })
},
- onSettled: () => {
- setIsDeleting(false)
- },
}
)
}
@@ -137,7 +144,30 @@ const RedirectUrls = () => {
)}
</Tooltip.Root>
</div>
- <RedirectUrlList canUpdate={canUpdateConfig} onSelectUrlToDelete={setSelectedUrlToDelete} />
+ {isLoading && (
+ <>
+ <ValueContainer>
+ <HorizontalShimmerWithIcon />
+ </ValueContainer>
+ <ValueContainer>
+ <HorizontalShimmerWithIcon />
+ </ValueContainer>
+ </>
+ )}
+ {isError && (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+ {isSuccess && (
+ <RedirectUrlList
+ URI_ALLOW_LIST_ARRAY={URI_ALLOW_LIST_ARRAY}
+ canUpdate={canUpdateConfig}
+ onSelectUrlToDelete={setSelectedUrlToDelete}
+ />
+ )}
<Modal
hideFooter
size="small"
@@ -152,7 +182,7 @@ const RedirectUrls = () => {
validationSchema={newUrlSchema}
onSubmit={onAddNewUrl}
>
- {({ isSubmitting }: { isSubmitting: boolean }) => {
+ {() => {
return (
<div className="mb-4 space-y-4 pt-4">
<div className="px-5">
@@ -172,8 +202,8 @@ const RedirectUrls = () => {
form="new-redirect-url-form"
htmlType="submit"
size="medium"
- disabled={isSubmitting}
- loading={isSubmitting}
+ disabled={isUpdatingConfig}
+ loading={isUpdatingConfig}
>
Add URL
</Button>
@@ -214,10 +244,10 @@ const RedirectUrls = () => {
block
size="medium"
type="warning"
- loading={isDeleting}
+ loading={isUpdatingConfig}
onClick={() => onConfirmDeleteUrl(selectedUrlToDelete)}
>
- {isDeleting ? 'Removing...' : 'Remove URL'}
+ {isUpdatingConfig ? 'Removing...' : 'Remove URL'}
</Button>
</div>
</div>
diff --git a/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx b/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx
index 2470fed6324..241f0063fbf 100644
--- a/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx
+++ b/studio/components/interfaces/Auth/SiteUrl/SiteUrl.tsx
@@ -1,7 +1,14 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { observer } from 'mobx-react-lite'
import { useEffect } from 'react'
-import { Form, Input } from 'ui'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Form,
+ IconAlertCircle,
+ Input,
+} from 'ui'
import { boolean, number, object, string } from 'yup'
import { useParams } from 'common'
@@ -16,48 +23,53 @@ import { useAuthConfigQuery } from 'data/auth/auth-config-query'
import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'
import { useCheckPermissions, useStore } from 'hooks'
+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 Captcha secret'),
+ }),
+})
+
const SiteUrl = observer(() => {
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data: config, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
+ const {
+ data: authConfig,
+ error: authConfigError,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
const formId = 'auth-config-general-form'
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
const INITIAL_VALUES = {
- 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 || '',
+ DISABLE_SIGNUP: authConfig?.DISABLE_SIGNUP,
+ JWT_EXP: authConfig?.JWT_EXP,
+ SITE_URL: authConfig?.SITE_URL,
+ REFRESH_TOKEN_ROTATION_ENABLED: authConfig?.REFRESH_TOKEN_ROTATION_ENABLED || false,
+ SECURITY_REFRESH_TOKEN_REUSE_INTERVAL: authConfig?.SECURITY_REFRESH_TOKEN_REUSE_INTERVAL,
+ SECURITY_CAPTCHA_ENABLED: authConfig?.SECURITY_CAPTCHA_ENABLED || false,
+ SECURITY_CAPTCHA_PROVIDER: authConfig?.SECURITY_CAPTCHA_PROVIDER || 'hcaptcha',
+ SECURITY_CAPTCHA_SECRET: authConfig?.SECURITY_CAPTCHA_SECRET || '',
}
- 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 Captcha secret'),
- }),
- })
-
- const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {
+ const onSubmit = (values: any, { resetForm }: any) => {
const payload = { ...values }
payload.DISABLE_SIGNUP = !values.DISABLE_SIGNUP
- setSubmitting(true)
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
@@ -74,22 +86,31 @@ const SiteUrl = observer(() => {
})
resetForm({ values: values, initialValues: values })
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
+ if (isError) {
+ return (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )
+ }
+
return (
<Form id={formId} initialValues={INITIAL_VALUES} onSubmit={onSubmit} validationSchema={schema}>
- {({ isSubmitting, handleReset, resetForm, values, initialValues }: any) => {
+ {({ handleReset, resetForm, values, initialValues }: any) => {
const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
// Form is reset once remote data is loaded in store
useEffect(() => {
- resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })
- }, [isLoaded])
+ if (isSuccess) {
+ resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES })
+ }
+ }, [isSuccess])
return (
<>
@@ -103,7 +124,7 @@ const SiteUrl = observer(() => {
<div className="flex py-4 px-8">
<FormActions
form={formId}
- isSubmitting={isSubmitting}
+ isSubmitting={isUpdatingConfig}
hasChanges={hasChanges}
handleReset={handleReset}
disabled={!canUpdateConfig}
@@ -117,7 +138,7 @@ const SiteUrl = observer(() => {
}
>
<FormSection>
- <FormSectionContent loading={!isLoaded}>
+ <FormSectionContent loading={isLoading}>
<Input
id="SITE_URL"
size="small"
diff --git a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
index 3bd9dffefd0..afc8ef964d1 100644
--- a/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
+++ b/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
@@ -8,6 +8,7 @@ import {
Alert_Shadcn_,
Button,
Form,
+ IconAlertCircle,
IconAlertTriangle,
IconEye,
IconEyeOff,
@@ -36,21 +37,27 @@ import { generateFormValues, isSmtpEnabled } from './SmtpForm.utils'
const SmtpForm = () => {
const { ui } = useStore()
const { ref: projectRef } = useParams()
- const { data: config, isLoading, isFetched: isLoaded } = useAuthConfigQuery({ projectRef })
- const { mutate: updateAuthConfig } = useAuthConfigUpdateMutation()
+ const {
+ data: authConfig,
+ error: authConfigError,
+ isLoading,
+ isError,
+ isSuccess,
+ } = useAuthConfigQuery({ projectRef })
+ const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation()
const [enableSmtp, setEnableSmtp] = useState(false)
const [hidden, setHidden] = useState(true)
const formId = 'auth-config-smtp-form'
- const initialValues = generateFormValues(config)
+ const initialValues = generateFormValues(authConfig)
const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')
useEffect(() => {
- if (isLoaded && isSmtpEnabled(config)) {
+ if (isSuccess && isSmtpEnabled(authConfig)) {
setEnableSmtp(true)
}
- }, [isLoaded, config])
+ }, [isSuccess, authConfig])
const schema = object({
SMTP_ADMIN_EMAIL: string().when([], {
@@ -115,14 +122,13 @@ const SmtpForm = () => {
}),
})
- const onSubmit = (values: any, { setSubmitting, resetForm }: any) => {
+ const onSubmit = (values: any, { resetForm }: any) => {
const payload = enableSmtp ? values : defaultDisabledSmtpFormValues
// Format payload: Remove redundant value + convert port to string
delete payload.ENABLE_SMTP
payload.SMTP_PORT = payload.SMTP_PORT ? payload.SMTP_PORT.toString() : payload.SMTP_PORT
- setSubmitting(true)
updateAuthConfig(
{ projectRef: projectRef!, config: payload },
{
@@ -135,16 +141,23 @@ const SmtpForm = () => {
resetForm({ values: updatedFormValues, initialValues: updatedFormValues })
ui.setNotification({ category: 'success', message: 'Successfully updated settings' })
},
- onSettled: () => {
- setSubmitting(false)
- },
}
)
}
+ if (isError) {
+ return (
+ <Alert_Shadcn_ variant="destructive">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )
+ }
+
return (
<Form id={formId} initialValues={initialValues} onSubmit={onSubmit} validationSchema={schema}>
- {({ isSubmitting, resetForm, values }: any) => {
+ {({ resetForm, values }: any) => {
const isValidSmtpConfig = isSmtpEnabled(values)
const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
@@ -152,11 +165,11 @@ const SmtpForm = () => {
// it won't error because the hooks are always rendered in the same order
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
- if (isLoaded) {
- const formValues = generateFormValues(config)
+ if (isSuccess) {
+ const formValues = generateFormValues(authConfig)
resetForm({ values: formValues, initialValues: formValues })
}
- }, [isLoaded, config])
+ }, [isSuccess, authConfig])
const onResetForm = () => {
setEnableSmtp(isSmtpEnabled(initialValues))
@@ -174,7 +187,7 @@ const SmtpForm = () => {
<div className="flex py-4 px-8">
<FormActions
form={formId}
- isSubmitting={isSubmitting}
+ isSubmitting={isUpdatingConfig}
hasChanges={hasChanges}
handleReset={onResetForm}
disabled={!canUpdateConfig}