The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore: add SMTP form
Jonathan Summers-Muireef88b4bdec7
diff --git a/studio/components/interfaces/Auth/RedirectDomains.tsx b/studio/components/interfaces/Auth/RedirectDomains.tsxindex 2048cbbe9f2..5f1720a1f16 100644--- a/studio/components/interfaces/Auth/RedirectDomains.tsx+++ b/studio/components/interfaces/Auth/RedirectDomains.tsx@@ -20,7 +20,7 @@ const RedirectDomains = () => {/***- * reges from: https://stackoverflow.com/a/68002755/4807782+ * regex from: https://stackoverflow.com/a/68002755/4807782** examples of matches:*diff --git a/studio/components/interfaces/Auth/SmtpForm.tsx b/studio/components/interfaces/Auth/SmtpForm.tsxnew file mode 100644index 00000000000..5aa6ce8f03c--- /dev/null+++ b/studio/components/interfaces/Auth/SmtpForm.tsx@@ -0,0 +1,338 @@+import { Alert, Form, Input, InputNumber, Loading, Toggle } from '@supabase/ui'+import { useStore } from 'hooks'+import { toJS } from 'mobx'+import { observer } from 'mobx-react-lite'+import auth from 'pages/project/[ref]/auth'+import React from 'react'+import { useState } from 'react'+import { useEffect } from 'react'+import { boolean, number, object, string } from 'yup'+import {+ FormActions,+ FormHeader,+ FormPanel,+ FormSection,+ FormSectionContent,+ FormSectionLabel,+} from '../../ui/Forms'++const SmtpForm = observer(() => {+ const { authConfig, ui } = useStore()+ const [enableSmtp, setEnableSmtp] = useState(false)++ function generateInitialValues(config: any) {+ return {+ ENABLE_SMTP: enableSmtp,+ SMTP_ADMIN_EMAIL: config.SMTP_ADMIN_EMAIL ?? '',+ SMTP_SENDER_NAME: config.SMTP_SENDER_NAME ?? '',+ SMTP_USER: config.SMTP_USER ?? '',+ SMTP_HOST: config.SMTP_HOST ?? '',+ SMTP_PASS: config.SMTP_PASS ?? '',+ SMTP_PORT: config.SMTP_PORT ?? 465,+ SMTP_MAX_FREQUENCY: config.SMTP_MAX_FREQUENCY ?? undefined,+ }+ }++ // const INITIAL_VALUES = generateInitialValues(authConfig.config)++ function checkSmtpState(config: any, resetForm: () => void) {+ console.log(+ config.SMTP_ADMIN_EMAIL,+ config.SMTP_SENDER_NAME,+ config.SMTP_USER,+ config.SMTP_HOST,+ config.SMTP_PASS,+ config.SMTP_PORT,+ config.SMTP_MAX_FREQUENCY+ )+ if (+ config.SMTP_ADMIN_EMAIL &&+ config.SMTP_SENDER_NAME &&+ config.SMTP_USER &&+ config.SMTP_HOST &&+ config.SMTP_PASS &&+ config.SMTP_PORT &&+ config.SMTP_MAX_FREQUENCY > 0+ ) {+ console.log('TRUE')+ setEnableSmtp(true)+ resetForm()+ } else {+ console.log('FALSE')+ setEnableSmtp(false)+ resetForm()+ }+ }++ /**+ * domain and IP address regex+ *+ * example of matches:+ *+ * "vercel.com"+ * "www.vercel.com"+ * "uptime-monitor-fe.vercel.app"+ * "https://uptime-monitor-fe.vercel.app/"+ * "127.0.0.0"+ *+ */+ const domainRegex =+ /^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_-]+(\.[a-zA-Z]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)?$|^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)$/gm++ const schema = object({+ SMTP_ADMIN_EMAIL: string().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) => schema.email('Must be a valid email').required('Admin Email is required'),+ otherwise: (schema) => schema,+ }),+ SMTP_SENDER_NAME: string().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) => schema.required('Sender name is required'),+ otherwise: (schema) => schema,+ }),+ SMTP_HOST: string().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) =>+ schema+ .matches(domainRegex, 'Must be a valid URL or IP address')+ .required('Host URL is required.'),+ otherwise: (schema) => schema,+ }),+ SMTP_PORT: number().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) =>+ schema+ .required('Port number is required.')+ .min(1, 'Must be a valid port number more than 0')+ .max(65535, 'Must be a valid port number no more than 65535'),+ otherwise: (schema) => schema,+ }),++ SMTP_MAX_FREQUENCY: number().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) =>+ schema.min(1, 'Must be more than 0').max(32767, 'Must not be more than 32,767 an hour'),+ otherwise: (schema) => schema,+ }),++ SMTP_USER: string().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) => schema.required('SMTP Username is required'),+ otherwise: (schema) => schema,+ }),+ SMTP_PASS: string().when([], {+ is: () => {+ return enableSmtp+ },+ then: (schema) => schema.required('SMTP password is required'),+ otherwise: (schema) => schema,+ }),+ })++ const isLoaded = authConfig.isLoaded++ return (+ <>+ <Form+ id="auth-config-general-form"+ initialValues={generateInitialValues(authConfig.config)}+ onSubmit={async (values: any, { setSubmitting, resetForm }: any) => {+ const payload = { ...values }+ payload.SMTP_PORT = values.SMTP_PORT.toString()++ // remove rendundant value+ delete payload.ENABLE_SMTP++ if (!enableSmtp) {+ payload.SMTP_ADMIN_EMAIL = null+ payload.SMTP_SENDER_NAME = null+ payload.SMTP_USER = null+ payload.SMTP_HOST = null+ payload.SMTP_PASS = null+ payload.SMTP_PORT = null+ payload.SMTP_MAX_FREQUENCY = 60+ }++ try {+ setSubmitting(true)+ await authConfig.update(payload)+ setSubmitting(false)+ ui.setNotification({+ category: 'success',+ message: `Updated settings`,+ })+ console.log('payload', payload)+ resetForm({+ values: !enableSmtp ? generateInitialValues(payload) : payload,+ initialValues: generateInitialValues(payload),+ })+ } catch (error) {+ ui.setNotification({+ category: 'error',+ message: `Failed to update settings`,+ })+ setSubmitting(false)+ }+ }}+ validationSchema={schema}+ >+ {({ isSubmitting, handleReset, resetForm, values, initialValues }: any) => {+ /**+ * Tracks changes in form+ */+ const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)++ /**+ * Form is reset once remote data is loaded in store+ */+ useEffect(() => {+ checkSmtpState(authConfig.config, () =>+ resetForm({+ values: generateInitialValues(authConfig.config),+ initialValues: generateInitialValues(authConfig.config),+ })+ )+ }, [authConfig.isLoaded])++ return (+ <>+ <FormHeader+ title="SMTP Settings"+ description={`You can use your own SMTP server instead of the built-in email service.`}+ />+ <FormPanel+ footer={+ <div className="flex justify-between py-4 px-8">+ <FormActions+ handleReset={handleReset}+ isSubmitting={isSubmitting}+ hasChanges={hasChanges}+ helper={'Learn more about global Auth settings'}+ />+ </div>+ }+ >+ <FormSection>+ <FormSectionContent loading={!isLoaded}>+ <Toggle+ name="ENABLE_SMTP"+ size="small"+ label="Enable Custom SMTP"+ layout="flex"+ onChange={() => {+ // resetForm({ values: values, initialValues: INITIAL_VALUES })+ setEnableSmtp(!enableSmtp)+ }}+ descriptionText="Emails will be sent using your custom SMTP provider"+ />+ </FormSectionContent>+ </FormSection>+ <div className="border-scale-400 border-t"></div>+ <FormSection+ header={<FormSectionLabel>Sender details</FormSectionLabel>}+ disabled={!enableSmtp}+ >+ <FormSectionContent loading={!isLoaded}>+ <Input+ name="SMTP_ADMIN_EMAIL"+ id="SMTP_ADMIN_EMAIL"+ label="Sender email"+ descriptionText="This is the email address the emails are sent from"+ placeholder="[email protected]"+ />+ <Input+ name="SMTP_SENDER_NAME"+ id="SMTP_SENDER_NAME"+ label="Sender name"+ descriptionText="Name displayed in the recipient's inbox"+ placeholder="The name shown on the email"+ />+ </FormSectionContent>+ </FormSection>+ <div className="border-scale-400 border-t"></div>+ <FormSection+ disabled={!enableSmtp}+ header={+ <FormSectionLabel>+ <span>SMTP Provider Settings</span>+ <p className="text-scale-900 my-4">+ Your SMTP Credentials will always be encrypted in our database.+ </p>+ </FormSectionLabel>+ }+ >+ <FormSectionContent loading={!isLoaded}>+ <Input+ name="SMTP_HOST"+ placeholder="your.smtp.host.com"+ id="SMTP_HOST"+ label="Host"+ descriptionText="Hostname or IP address of your SMTP server."+ />++ <Input+ type="number"+ name="SMTP_PORT"+ placeholder="587"+ id="SMTP_PORT"+ label="Port number"+ // @ts-ignore+ descriptionText={+ <>+ <span className="block">+ Port used by your SMTP server. Common ports include 25, 465, and 587.{' '}+ </span>+ <span className="mt-2 block">+ Avoid using port 25 as modern SMTP email clients shouldn't use this+ port, it is traditionally blocked by residential ISPs and Cloud Hosting+ Providers, to curb the amount of spam.+ </span>+ </>+ }+ />+ <Input+ type="number"+ name="SMTP_MAX_FREQUENCY"+ id="SMTP_MAX_FREQUENCY"+ min={0}+ label="Rate limit"+ descriptionText="Maximum number of emails sent per hour"+ actions={<span className="text-scale-900 mr-3">emails per hour</span>}+ />++ <Input+ name="SMTP_USER"+ id="SMTP_USER"+ label="Username"+ placeholder="SMTP Username"+ />+ <Input+ name="SMTP_PASS"+ id="SMTP_PASS"+ label="Password"+ placeholder="SMTP Password"+ />+ </FormSectionContent>+ </FormSection>+ </FormPanel>+ </>+ )+ }}+ </Form>+ </>+ )+})++export { SmtpForm }diff --git a/studio/components/interfaces/Auth/index.tsx b/studio/components/interfaces/Auth/index.tsxindex 967ecf63bc8..a8a7bdfbee1 100644--- a/studio/components/interfaces/Auth/index.tsx+++ b/studio/components/interfaces/Auth/index.tsx@@ -1,3 +1,4 @@import AuthProvidersForm from './AuthProvidersForm'+import { SmtpForm } from './SmtpForm'-export { AuthProvidersForm }+export { AuthProvidersForm, SmtpForm }diff --git a/studio/components/ui/Forms/FormActions.tsx b/studio/components/ui/Forms/FormActions.tsxindex 5fb2e8dcd20..88b27ee335d 100644--- a/studio/components/ui/Forms/FormActions.tsx+++ b/studio/components/ui/Forms/FormActions.tsx@@ -24,7 +24,12 @@ const FormActions = ({ isSubmitting, handleReset, hasChanges = undefined, helper<div className="flex w-full items-center justify-between gap-2">{helper && <span className="text-scale-900 text-xs">{helper}</span>}<div className="flex justify-between gap-2">- <Button type="default" htmlType="reset" onClick={() => handleReset()}>+ <Button+ disabled={!hasChanges && hasChanges !== undefined}+ type="default"+ htmlType="reset"+ onClick={() => handleReset()}+ >Cancel</Button><Buttondiff --git a/studio/components/ui/Forms/FormSection.tsx b/studio/components/ui/Forms/FormSection.tsxindex 3f983ea99ec..5b4436d7dc4 100644--- a/studio/components/ui/Forms/FormSection.tsx+++ b/studio/components/ui/Forms/FormSection.tsx@@ -1,18 +1,28 @@const FormSection = ({children,header,+ disabled,}: {children: React.ReactNodeheader?: React.ReactNode-}) => (- <div className="grid grid-cols-12 gap-6 px-8 py-2">- {header}- {children}- </div>-)+ disabled?: boolean+}) => {+ const classes = `+ grid grid-cols-12 gap-6 px-8 py-2 lg:gap-12+ transition-opacity+ ${disabled ? 'opacity-30 pointer-events-none' : 'opacity-100'}+ `++ return (+ <div className={classes}>+ {header}+ {children}+ </div>+ )+}const FormSectionLabel = ({ children }: { children: React.ReactNode | string }) => {- return <label className="text-scale-1200 col-span-12 text-sm lg:col-span-4">{children}</label>+ return <label className="text-scale-1200 col-span-12 text-sm lg:col-span-5">{children}</label>}const FormSectionContent = ({children,@@ -22,7 +32,7 @@ const FormSectionContent = ({loading?: boolean}) => {return (- <div className="relative col-span-12 flex flex-col gap-6 lg:col-span-8">+ <div className="relative col-span-12 flex flex-col gap-6 lg:col-span-7">{loading ? (<div className="flex w-full flex-col gap-2"><div className="shimmering-loader h-2 w-1/3 rounded"></div>diff --git a/studio/pages/project/[ref]/auth/templates-new.tsx b/studio/pages/project/[ref]/auth/templates-new.tsxindex 2d6156c1129..04f59cb4e46 100644--- a/studio/pages/project/[ref]/auth/templates-new.tsx+++ b/studio/pages/project/[ref]/auth/templates-new.tsx@@ -1,602 +1,30 @@-import {- Button,- Collapsible,- Form,- IconArrowRight,- IconCheck,- IconChevronUp,- IconGlobe,- IconTrash,- IconX,- Input,- InputNumber,- Modal,- Tabs,- Toggle,-} from '@supabase/ui'+import { SmtpForm } from 'components/interfaces'import { AuthLayout } from 'components/layouts'-import AutoSchemaForm from 'components/interfaces/Auth/AutoSchemaForm'-import { withAuth } from 'hooks'+import { FormsContainer } from 'components/ui/Forms'+import { useStore } from 'hooks'import { observer } from 'mobx-react-lite'-import React, { useReducer, useState } from 'react'-import AuthFormSchema from './AuthFormSchema'--// import GoogleIcon './../../../static/icons/google-icon.svg'--const DocsButton = () => {- return (- <button- className="- bg-scale-300- dark:bg-scale-100- border-scale-500- hover:border-scale-700- dark:border-scale-300- dark:hover:border-scale-500 group- my-6 flex- w-full items-center- gap-6- rounded-md border px-6- py-4 text-left- shadow-sm- transition- "- >- <div className="bg-brand-900 h-10 w-10 rounded p-1 transition duration-500 group-hover:-rotate-3 group-hover:scale-110">- {/* <img- className="text-white w-12 h-12"- src="/icons/docs-illustration.svg"- /> */}- </div>- <div className="grow">- <h3 className="text-scale-1200">Use authentication as the backbone of your app</h3>- <p className="text-scale-900 text-xs">- Learn how to use Supabase Auth with Auth Policies to pick and choose what users see what.- </p>- <p className="text-brand-900 mt-2 flex items-center gap-1 text-xs">- See Documenation- <span className="transition group-hover:translate-x-1">- <IconArrowRight strokeWidth={2} width={12} />- </span>- </p>- </div>- <div className="text-scale-900">- <IconX />- </div>- </button>- )-}--const CardForm = () => {- // panel- const Panel = ({- children,- header,- footer,- }: {- children: React.ReactNode- header?: React.ReactNode- footer?: React.ReactNode- }) => (- <div- className="- bg-scale-100- dark:bg-scale-300-- border-scale-400 my-8 overflow-hidden rounded-md border shadow"- >- {header && (- <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">- {header}- </div>- )}- <div className="space-y-6 py-6">{children}</div>- {footer}- </div>- )-- const Section = ({- children,- header,- }: {- children: React.ReactNode- header?: React.ReactNode- }) => (- <div className="grid grid-cols-12 px-8 py-2">- {header}- {children}- </div>- )-- return (- <>- <AutoSchemaForm />- <Form- id="general_form"- initialValues={{- enable_signups: true,- jwt_expiry: 3600,- }}- onSubmit={(values: any, { setSubmitting }: any) => {- setTimeout(() => {- alert(JSON.stringify(values, null, 2))- setSubmitting(false)- }, 400)- }}- validate={(values: Values) => {- const errors: any = {}- if (!values.jwt_expiry) {- errors.jwt_expiry = 'This is required'- }- if (values.jwt_expiry > 604800) {- errors.jwt_expiry =- 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'- }- return errors- }}- >- {({ isSubmitting, handleReset }: any) => (- <Panel- footer={- <>- <div className="border-scale-400 border-t"></div>- <div className="flex justify-end gap-2 py-3 px-6">- <Button type="default" htmlType="reset" onClick={() => handleReset()}>- Cancel- </Button>- <Button- loading={isSubmitting}- type="primary"- htmlType="submit"- form="general_form"- >- Save- </Button>- </div>- </>- }- >- <Section- header={<label className="text-scale-1200 col-span-4 text-sm">User Signups</label>}- >- <Toggle- id="enable_signups"- className="col-span-8"- label="Allow new users to sign up"- layout="flex"- descriptionText="If this is disabled, new users will not be able to sign up to your application."- />- </Section>- <div className="border-scale-400 border-t"></div>- <Section- header={<label className="text-scale-1200 col-span-4 text-sm">User Sessions</label>}- >- <InputNumber- className="col-span-8"- id="jwt_expiry"- label="JWT expiry limit"- descriptionText="How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 seconds (one week)."- />- </Section>- </Panel>- )}- </Form>- </>- )-}--// type to do later..-let initialState: any = {}--AuthFormSchema.map((provider) => {- initialState[`${provider.name.toLowerCase()}-active`] = provider.name == 'Email' ? true : false- initialState[`${provider.name.toLowerCase()}-app-id`] = ''- initialState[`${provider.name.toLowerCase()}-id-key`] = ''-})--console.log('form initialState', initialState)--function providersReducer(state: any, action: any) {- switch (action.type) {- case 'update':- return Object.assign(state, action.values)- // case 'decrement':- // return { count: state.count - 1 }- default:- throw new Error()+import { useEffect } from 'react'+import { NextPageWithLayout } from 'types'++const PageLayout: NextPageWithLayout = () => {+ const { ui, authConfig } = useStore()++ useEffect(() => {+ // temporary store loader+ authConfig.load()+ }, [ui.selectedProjectRef])++ if (authConfig) {+ return (+ <FormsContainer>+ <SmtpForm />+ </FormsContainer>+ )}}-const SmtpForm = () => {- const [active, setActive] = useState(true)-- // panel- const Panel = ({- children,- header,- footer,- }: {- children: React.ReactNode- header?: React.ReactNode- footer?: React.ReactNode- }) => (- <div- className="- bg-scale-100- dark:bg-scale-300-- border-scale-400 my-8 overflow-hidden rounded-md border shadow"- >- {header && (- <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">- {header}- </div>- )}- <div className="space-y-6 py-6">{children}</div>- {footer}- </div>- )-- const Section = ({- children,- header,- }: {- children: React.ReactNode- header?: React.ReactNode- }) => (- <div className="grid grid-cols-12 gap-8 px-8 py-2">- {header && <div className="col-span-4">{header}</div>}- {children}- </div>- )-- return (- <>- <Form- id="general_form"- initialValues={{- enable_smtp: false,- jwt_expiry: 3600,- }}- onSubmit={(values: any, { setSubmitting }: any) => {- setTimeout(() => {- alert(JSON.stringify(values, null, 2))- setSubmitting(false)- }, 400)- }}- validate={(values: Values) => {- const errors: any = {}- if (!values.jwt_expiry) {- errors.jwt_expiry = 'This is required'- }- if (values.jwt_expiry > 604800) {- errors.jwt_expiry =- 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'- }- return errors- }}- >- {({ isSubmitting, handleReset, values }: any) => (- <Panel- footer={- <>- <div className="border-scale-400 border-t"></div>- <div className="flex justify-end gap-2 py-3 px-6">- <Button- loading={isSubmitting}- type="secondary"- htmlType="reset"- onClick={() => handleReset()}- >- Cancel- </Button>- <Button- loading={isSubmitting}- type="primary"- htmlType="submit"- form="general_form"- >- Save- </Button>- </div>- </>- }- >- {/* <Section- header={- <label className="text-sm text-scale-1200 col-span-4">- Enable SMTP- </label>- }- > */}- <Toggle- // onChange={() => setActive(!active)}- // checked={active}- name="enable_smtp"- className="col-span-8 mx-8"- label="Enable Custom SMTP"- layout="flex"- descriptionText="If this is disabled, new users will not be able to sign up to your application."- />- {/* </Section> */}- <div className="border-scale-400 border-t"></div>- <Section- header={- <div className="w-full">- <label className="text-scale-1100 text-sm">SMTP details</label>- <p className="text-scale-900 text-sm">- These settings can be found in your SMTP provider config- </p>- </div>- }- >- <div className="col-span-8 space-y-6">- <Input label="Sender address" type="url" disabled={!values.enable_smtp} />- <Input label="SMTP server host" disabled={!values.enable_smtp} />- <InputNumber label="SMTP server port" disabled={!values.enable_smtp} />- <Input label="SMTP account username" disabled={!values.enable_smtp} />- <Input- label="SMTP account password"- type="password"- disabled={!values.enable_smtp}- />- </div>- </Section>- {values.enable_smtp && (- <div className="mx-8">- <DocsButton />- </div>- )}- </Panel>- )}- </Form>- </>- )-}--const TemplatesForm = () => {- const [active, setActive] = useState(true)-- // panel- const Panel = ({- children,- header,- footer,- }: {- children: React.ReactNode- header?: React.ReactNode- footer?: React.ReactNode- }) => (- <div- className="- bg-scale-100- dark:bg-scale-300- border-scale-400 mb-8 overflow-hidden rounded-md border shadow"- >- {header && (- <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">- {header}- </div>- )}- <div className="space-y-6 py-6">{children}</div>- {footer}- </div>- )-- const Section = ({- children,- header,- }: {- children: React.ReactNode- header?: React.ReactNode- }) => (- <div className="grid grid-cols-12 gap-8 px-8 py-2">- {header && <div className="col-span-4">{header}</div>}- {children}- </div>- )-- return (- <>- <Form- id="general_form"- initialValues={{- enable_smtp: false,- jwt_expiry: 3600,- }}- onSubmit={(values: any, { setSubmitting }: any) => {- setTimeout(() => {- alert(JSON.stringify(values, null, 2))- setSubmitting(false)- }, 400)- }}- validate={(values: Values) => {- const errors: any = {}- if (!values.jwt_expiry) {- errors.jwt_expiry = 'This is required'- }- if (values.jwt_expiry > 604800) {- errors.jwt_expiry =- 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'- }- return errors- }}- >- {({ isSubmitting, handleReset, values }: any) => (- <>- <div className="my-4">- <Tabs- defaultActiveId="confirm_signup"- type="underlined"- // listClassNames="px-8"- size="medium"- >- <Tabs.Panel id={'confirm_signup'} label="Confirm Signup" />- <Tabs.Panel id={'reset_password'} label="Reset Password" />- <Tabs.Panel id={'magic_link'} label="Magic Link" />- <Tabs.Panel id={'change_email_address'} label="Change Email Address" />- <Tabs.Panel id={'invite_user'} label="Invite User" />- </Tabs>- </div>- <Panel- footer={- <>- <div className="border-scale-400 border-t"></div>- <div className="flex justify-end gap-2 py-3 px-6">- <Button- loading={isSubmitting}- type="secondary"- htmlType="reset"- onClick={() => handleReset()}- >- Cancel- </Button>- <Button- loading={isSubmitting}- type="primary"- htmlType="submit"- form="general_form"- >- Save- </Button>- </div>- </>- }- >- {/* <Section- header={- <label className="text-sm text-scale-1200 col-span-4">- Enable SMTP- </label>- }- > */}- {/* <Toggle- // onChange={() => setActive(!active)}- // checked={active}- name="enable_smtp"- className="col-span-8 mx-8"- label="Enable Custom SMTP"- layout="flex"- descriptionText="If this is disabled, new users will not be able to sign up to your application."- /> */}- {/* </Section> */}- {/* <div className="border-t border-scale-400"></div> */}- <Section- header={- <div className="w-full">- <h3 className="text-scale-1200 mb-4 text-base">Confirm Signup</h3>- <p className="text-scale-900 text-sm">- When a user signs up using an email address and password, you can send them a- confirmation email to verify their registered email address. Learn more- </p>- </div>- }- >- <div className="col-span-8 space-y-6">- <Input label="Sender address" type="url" />- <Input label="SMTP server host" />- <InputNumber label="SMTP server port" />- <Input label="SMTP account username" />- <Input.TextArea- label="SMTP account password"- type="password"- rows={8}- defaultValue={`<h2>Confirm your signup</h2>--<p>Follow this link to confirm your user:</p>-<p><a href="{{ .ConfirmationURL }}">Confirm your mail</a></p>- `}- />- </div>- </Section>- {values.enable_smtp && (- <div className="mx-8">- <DocsButton />- </div>- )}- </Panel>- </>- )}- </Form>- </>- )-}--const Auth = () => {- return (- <AuthLayout title="Auth">- <div className="p-4">- <WholeForm />- </div>- </AuthLayout>- )-}--export function WholeForm() {- return (- <div style={{ width: '820px' }} className="mx-auto">- <div className="animate-fade-in space-y-12 py-12">- <div>- <h1 className="text-scale-1200 text-3xl">Emails</h1>- </div>- <button- className="- bg-scale-300- dark:bg-scale-100- border-scale-500- hover:border-scale-700- dark:border-scale-300- dark:hover:border-scale-500 group- my-6 flex- w-full items-center- gap-6- rounded-md border px-6- py-4 text-left- shadow-sm- transition- "- >- <div className="bg-brand-900 h-10 w-10 rounded p-1 transition duration-500 group-hover:-rotate-3 group-hover:scale-110">- {/* <img- className="text-white w-12 h-12"- src="/icons/docs-illustration.svg"- /> */}- </div>- <div className="grow">- <h3 className="text-scale-1200">Use authentication as the backbone of your app</h3>- <p className="text-scale-900 text-xs">- Learn how to use Supabase Auth with Auth Policies to pick and choose what users see- what.- </p>- <p className="text-brand-900 mt-2 flex items-center gap-1 text-xs">- See Documenation- <span className="transition group-hover:translate-x-1">- <IconArrowRight strokeWidth={2} width={12} />- </span>- </p>- </div>- <div className="text-scale-900">- <IconX />- </div>- </button>- <div className="border-scale-400 border-t"></div>- <div>- <h3 className="text-scale-1200 mb-2 text-2xl">Custom SMTP</h3>- <p className="text-scale-900 text-sm">- You can use your own SMTP server instead of the built-in email service.- </p>- <SmtpForm />- </div>- <div>- <h3 className="text-scale-1200 mb-2 text-2xl">Templates</h3>- <p className="text-scale-900 text-sm">- You can use your own SMTP server instead of the built-in email service.- </p>- <TemplatesForm />- </div>- </div>- </div>- )+PageLayout.getLayout = (page) => {+ return <AuthLayout>{page}</AuthLayout>}-export default withAuth(observer(Auth))+export default observer(PageLayout)diff --git a/studio/pages/project/[ref]/auth/templates-oldd.tsx b/studio/pages/project/[ref]/auth/templates-oldd.tsxnew file mode 100644index 00000000000..2d6156c1129--- /dev/null+++ b/studio/pages/project/[ref]/auth/templates-oldd.tsx@@ -0,0 +1,602 @@+import {+ Button,+ Collapsible,+ Form,+ IconArrowRight,+ IconCheck,+ IconChevronUp,+ IconGlobe,+ IconTrash,+ IconX,+ Input,+ InputNumber,+ Modal,+ Tabs,+ Toggle,+} from '@supabase/ui'+import { AuthLayout } from 'components/layouts'+import AutoSchemaForm from 'components/interfaces/Auth/AutoSchemaForm'+import { withAuth } from 'hooks'+import { observer } from 'mobx-react-lite'+import React, { useReducer, useState } from 'react'+import AuthFormSchema from './AuthFormSchema'++// import GoogleIcon './../../../static/icons/google-icon.svg'++const DocsButton = () => {+ return (+ <button+ className="+ bg-scale-300+ dark:bg-scale-100+ border-scale-500+ hover:border-scale-700+ dark:border-scale-300+ dark:hover:border-scale-500 group+ my-6 flex+ w-full items-center+ gap-6+ rounded-md border px-6+ py-4 text-left+ shadow-sm+ transition+ "+ >+ <div className="bg-brand-900 h-10 w-10 rounded p-1 transition duration-500 group-hover:-rotate-3 group-hover:scale-110">+ {/* <img+ className="text-white w-12 h-12"+ src="/icons/docs-illustration.svg"+ /> */}+ </div>+ <div className="grow">+ <h3 className="text-scale-1200">Use authentication as the backbone of your app</h3>+ <p className="text-scale-900 text-xs">+ Learn how to use Supabase Auth with Auth Policies to pick and choose what users see what.+ </p>+ <p className="text-brand-900 mt-2 flex items-center gap-1 text-xs">+ See Documenation+ <span className="transition group-hover:translate-x-1">+ <IconArrowRight strokeWidth={2} width={12} />+ </span>+ </p>+ </div>+ <div className="text-scale-900">+ <IconX />+ </div>+ </button>+ )+}++const CardForm = () => {+ // panel+ const Panel = ({+ children,+ header,+ footer,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ footer?: React.ReactNode+ }) => (+ <div+ className="+ bg-scale-100+ dark:bg-scale-300++ border-scale-400 my-8 overflow-hidden rounded-md border shadow"+ >+ {header && (+ <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">+ {header}+ </div>+ )}+ <div className="space-y-6 py-6">{children}</div>+ {footer}+ </div>+ )++ const Section = ({+ children,+ header,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ }) => (+ <div className="grid grid-cols-12 px-8 py-2">+ {header}+ {children}+ </div>+ )++ return (+ <>+ <AutoSchemaForm />+ <Form+ id="general_form"+ initialValues={{+ enable_signups: true,+ jwt_expiry: 3600,+ }}+ onSubmit={(values: any, { setSubmitting }: any) => {+ setTimeout(() => {+ alert(JSON.stringify(values, null, 2))+ setSubmitting(false)+ }, 400)+ }}+ validate={(values: Values) => {+ const errors: any = {}+ if (!values.jwt_expiry) {+ errors.jwt_expiry = 'This is required'+ }+ if (values.jwt_expiry > 604800) {+ errors.jwt_expiry =+ 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'+ }+ return errors+ }}+ >+ {({ isSubmitting, handleReset }: any) => (+ <Panel+ footer={+ <>+ <div className="border-scale-400 border-t"></div>+ <div className="flex justify-end gap-2 py-3 px-6">+ <Button type="default" htmlType="reset" onClick={() => handleReset()}>+ Cancel+ </Button>+ <Button+ loading={isSubmitting}+ type="primary"+ htmlType="submit"+ form="general_form"+ >+ Save+ </Button>+ </div>+ </>+ }+ >+ <Section+ header={<label className="text-scale-1200 col-span-4 text-sm">User Signups</label>}+ >+ <Toggle+ id="enable_signups"+ className="col-span-8"+ label="Allow new users to sign up"+ layout="flex"+ descriptionText="If this is disabled, new users will not be able to sign up to your application."+ />+ </Section>+ <div className="border-scale-400 border-t"></div>+ <Section+ header={<label className="text-scale-1200 col-span-4 text-sm">User Sessions</label>}+ >+ <InputNumber+ className="col-span-8"+ id="jwt_expiry"+ label="JWT expiry limit"+ descriptionText="How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 seconds (one week)."+ />+ </Section>+ </Panel>+ )}+ </Form>+ </>+ )+}++// type to do later..+let initialState: any = {}++AuthFormSchema.map((provider) => {+ initialState[`${provider.name.toLowerCase()}-active`] = provider.name == 'Email' ? true : false+ initialState[`${provider.name.toLowerCase()}-app-id`] = ''+ initialState[`${provider.name.toLowerCase()}-id-key`] = ''+})++console.log('form initialState', initialState)++function providersReducer(state: any, action: any) {+ switch (action.type) {+ case 'update':+ return Object.assign(state, action.values)+ // case 'decrement':+ // return { count: state.count - 1 }+ default:+ throw new Error()+ }+}++const SmtpForm = () => {+ const [active, setActive] = useState(true)++ // panel+ const Panel = ({+ children,+ header,+ footer,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ footer?: React.ReactNode+ }) => (+ <div+ className="+ bg-scale-100+ dark:bg-scale-300++ border-scale-400 my-8 overflow-hidden rounded-md border shadow"+ >+ {header && (+ <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">+ {header}+ </div>+ )}+ <div className="space-y-6 py-6">{children}</div>+ {footer}+ </div>+ )++ const Section = ({+ children,+ header,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ }) => (+ <div className="grid grid-cols-12 gap-8 px-8 py-2">+ {header && <div className="col-span-4">{header}</div>}+ {children}+ </div>+ )++ return (+ <>+ <Form+ id="general_form"+ initialValues={{+ enable_smtp: false,+ jwt_expiry: 3600,+ }}+ onSubmit={(values: any, { setSubmitting }: any) => {+ setTimeout(() => {+ alert(JSON.stringify(values, null, 2))+ setSubmitting(false)+ }, 400)+ }}+ validate={(values: Values) => {+ const errors: any = {}+ if (!values.jwt_expiry) {+ errors.jwt_expiry = 'This is required'+ }+ if (values.jwt_expiry > 604800) {+ errors.jwt_expiry =+ 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'+ }+ return errors+ }}+ >+ {({ isSubmitting, handleReset, values }: any) => (+ <Panel+ footer={+ <>+ <div className="border-scale-400 border-t"></div>+ <div className="flex justify-end gap-2 py-3 px-6">+ <Button+ loading={isSubmitting}+ type="secondary"+ htmlType="reset"+ onClick={() => handleReset()}+ >+ Cancel+ </Button>+ <Button+ loading={isSubmitting}+ type="primary"+ htmlType="submit"+ form="general_form"+ >+ Save+ </Button>+ </div>+ </>+ }+ >+ {/* <Section+ header={+ <label className="text-sm text-scale-1200 col-span-4">+ Enable SMTP+ </label>+ }+ > */}+ <Toggle+ // onChange={() => setActive(!active)}+ // checked={active}+ name="enable_smtp"+ className="col-span-8 mx-8"+ label="Enable Custom SMTP"+ layout="flex"+ descriptionText="If this is disabled, new users will not be able to sign up to your application."+ />+ {/* </Section> */}+ <div className="border-scale-400 border-t"></div>+ <Section+ header={+ <div className="w-full">+ <label className="text-scale-1100 text-sm">SMTP details</label>+ <p className="text-scale-900 text-sm">+ These settings can be found in your SMTP provider config+ </p>+ </div>+ }+ >+ <div className="col-span-8 space-y-6">+ <Input label="Sender address" type="url" disabled={!values.enable_smtp} />+ <Input label="SMTP server host" disabled={!values.enable_smtp} />+ <InputNumber label="SMTP server port" disabled={!values.enable_smtp} />+ <Input label="SMTP account username" disabled={!values.enable_smtp} />+ <Input+ label="SMTP account password"+ type="password"+ disabled={!values.enable_smtp}+ />+ </div>+ </Section>+ {values.enable_smtp && (+ <div className="mx-8">+ <DocsButton />+ </div>+ )}+ </Panel>+ )}+ </Form>+ </>+ )+}++const TemplatesForm = () => {+ const [active, setActive] = useState(true)++ // panel+ const Panel = ({+ children,+ header,+ footer,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ footer?: React.ReactNode+ }) => (+ <div+ className="+ bg-scale-100+ dark:bg-scale-300+ border-scale-400 mb-8 overflow-hidden rounded-md border shadow"+ >+ {header && (+ <div className="bg-scale-100 dark:bg-scale-200 border-scale-400 border-b px-8 py-4">+ {header}+ </div>+ )}+ <div className="space-y-6 py-6">{children}</div>+ {footer}+ </div>+ )++ const Section = ({+ children,+ header,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ }) => (+ <div className="grid grid-cols-12 gap-8 px-8 py-2">+ {header && <div className="col-span-4">{header}</div>}+ {children}+ </div>+ )++ return (+ <>+ <Form+ id="general_form"+ initialValues={{+ enable_smtp: false,+ jwt_expiry: 3600,+ }}+ onSubmit={(values: any, { setSubmitting }: any) => {+ setTimeout(() => {+ alert(JSON.stringify(values, null, 2))+ setSubmitting(false)+ }, 400)+ }}+ validate={(values: Values) => {+ const errors: any = {}+ if (!values.jwt_expiry) {+ errors.jwt_expiry = 'This is required'+ }+ if (values.jwt_expiry > 604800) {+ errors.jwt_expiry =+ 'The maxiumum allowed is 604,800 seconds. Use a smaller number of seconds.'+ }+ return errors+ }}+ >+ {({ isSubmitting, handleReset, values }: any) => (+ <>+ <div className="my-4">+ <Tabs+ defaultActiveId="confirm_signup"+ type="underlined"+ // listClassNames="px-8"+ size="medium"+ >+ <Tabs.Panel id={'confirm_signup'} label="Confirm Signup" />+ <Tabs.Panel id={'reset_password'} label="Reset Password" />+ <Tabs.Panel id={'magic_link'} label="Magic Link" />+ <Tabs.Panel id={'change_email_address'} label="Change Email Address" />+ <Tabs.Panel id={'invite_user'} label="Invite User" />+ </Tabs>+ </div>+ <Panel+ footer={+ <>+ <div className="border-scale-400 border-t"></div>+ <div className="flex justify-end gap-2 py-3 px-6">+ <Button+ loading={isSubmitting}+ type="secondary"+ htmlType="reset"+ onClick={() => handleReset()}+ >+ Cancel+ </Button>+ <Button+ loading={isSubmitting}+ type="primary"+ htmlType="submit"+ form="general_form"+ >+ Save+ </Button>+ </div>+ </>+ }+ >+ {/* <Section+ header={+ <label className="text-sm text-scale-1200 col-span-4">+ Enable SMTP+ </label>+ }+ > */}+ {/* <Toggle+ // onChange={() => setActive(!active)}+ // checked={active}+ name="enable_smtp"+ className="col-span-8 mx-8"+ label="Enable Custom SMTP"+ layout="flex"+ descriptionText="If this is disabled, new users will not be able to sign up to your application."+ /> */}+ {/* </Section> */}+ {/* <div className="border-t border-scale-400"></div> */}+ <Section+ header={+ <div className="w-full">+ <h3 className="text-scale-1200 mb-4 text-base">Confirm Signup</h3>+ <p className="text-scale-900 text-sm">+ When a user signs up using an email address and password, you can send them a+ confirmation email to verify their registered email address. Learn more+ </p>+ </div>+ }+ >+ <div className="col-span-8 space-y-6">+ <Input label="Sender address" type="url" />+ <Input label="SMTP server host" />+ <InputNumber label="SMTP server port" />+ <Input label="SMTP account username" />+ <Input.TextArea+ label="SMTP account password"+ type="password"+ rows={8}+ defaultValue={`<h2>Confirm your signup</h2>++<p>Follow this link to confirm your user:</p>+<p><a href="{{ .ConfirmationURL }}">Confirm your mail</a></p>+ `}+ />+ </div>+ </Section>+ {values.enable_smtp && (+ <div className="mx-8">+ <DocsButton />+ </div>+ )}+ </Panel>+ </>+ )}+ </Form>+ </>+ )+}++const Auth = () => {+ return (+ <AuthLayout title="Auth">+ <div className="p-4">+ <WholeForm />+ </div>+ </AuthLayout>+ )+}++export function WholeForm() {+ return (+ <div style={{ width: '820px' }} className="mx-auto">+ <div className="animate-fade-in space-y-12 py-12">+ <div>+ <h1 className="text-scale-1200 text-3xl">Emails</h1>+ </div>+ <button+ className="+ bg-scale-300+ dark:bg-scale-100+ border-scale-500+ hover:border-scale-700+ dark:border-scale-300+ dark:hover:border-scale-500 group+ my-6 flex+ w-full items-center+ gap-6+ rounded-md border px-6+ py-4 text-left+ shadow-sm+ transition+ "+ >+ <div className="bg-brand-900 h-10 w-10 rounded p-1 transition duration-500 group-hover:-rotate-3 group-hover:scale-110">+ {/* <img+ className="text-white w-12 h-12"+ src="/icons/docs-illustration.svg"+ /> */}+ </div>+ <div className="grow">+ <h3 className="text-scale-1200">Use authentication as the backbone of your app</h3>+ <p className="text-scale-900 text-xs">+ Learn how to use Supabase Auth with Auth Policies to pick and choose what users see+ what.+ </p>+ <p className="text-brand-900 mt-2 flex items-center gap-1 text-xs">+ See Documenation+ <span className="transition group-hover:translate-x-1">+ <IconArrowRight strokeWidth={2} width={12} />+ </span>+ </p>+ </div>+ <div className="text-scale-900">+ <IconX />+ </div>+ </button>+ <div className="border-scale-400 border-t"></div>+ <div>+ <h3 className="text-scale-1200 mb-2 text-2xl">Custom SMTP</h3>+ <p className="text-scale-900 text-sm">+ You can use your own SMTP server instead of the built-in email service.+ </p>+ <SmtpForm />+ </div>+ <div>+ <h3 className="text-scale-1200 mb-2 text-2xl">Templates</h3>+ <p className="text-scale-900 text-sm">+ You can use your own SMTP server instead of the built-in email service.+ </p>+ <TemplatesForm />+ </div>+ </div>+ </div>+ )+}++export default withAuth(observer(Auth))