The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
started moving forms in auth
Jonathan Summers-Muirae444359fe6c
diff --git a/studio/components/layouts/AuthLayout/AuthLayout.utils.ts b/studio/components/layouts/AuthLayout/AuthLayout.utils.tsindex 7ce9f4e3d68..ab9490d0752 100644--- a/studio/components/layouts/AuthLayout/AuthLayout.utils.ts+++ b/studio/components/layouts/AuthLayout/AuthLayout.utils.ts@@ -22,6 +22,18 @@ export const generateAuthMenu = (ref: string): ProductMenuGroup[] => {url: `/project/${ref}/auth/settings`,items: [],},+ {+ name: 'Settings new',+ key: 'settings-new',+ url: `/project/${ref}/auth/settings-new`,+ items: [],+ },+ {+ name: 'Templates',+ key: 'settings-templates',+ url: `/project/${ref}/auth/templates-new`,+ items: [],+ },],},]diff --git a/studio/components/ui/Forms/AutoSchemaForm.tsx b/studio/components/ui/Forms/AutoSchemaForm.tsxnew file mode 100644index 00000000000..aa26c19ff50--- /dev/null+++ b/studio/components/ui/Forms/AutoSchemaForm.tsx@@ -0,0 +1,121 @@+import { Button, Form, InputNumber, Toggle } from '@supabase/ui'+import React from 'react'++const AutoSchemaForm = () => {+ // 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 (+ <>+ <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: any) => {+ 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>+ </>+ )+}++export { AutoSchemaForm }diff --git a/studio/components/ui/Forms/FormsContainer.tsx b/studio/components/ui/Forms/FormsContainer.tsxnew file mode 100644index 00000000000..6b6d73723ce--- /dev/null+++ b/studio/components/ui/Forms/FormsContainer.tsx@@ -0,0 +1,5 @@+function FormsContainer(props: { children: React.ReactNode }) {+ return <div className="max-w-6xl py-12">{props.children}</div>+}++export { FormsContainer }diff --git a/studio/components/ui/Forms/index.tsx b/studio/components/ui/Forms/index.tsxnew file mode 100644index 00000000000..6c861848519--- /dev/null+++ b/studio/components/ui/Forms/index.tsx@@ -0,0 +1,2 @@+export * from './FormsContainer'+export * from './AutoSchemaForm'diff --git a/studio/pages/new/[slug].tsx b/studio/pages/new/[slug].tsxindex b8d9107377c..dd7d3a2ce44 100644--- a/studio/pages/new/[slug].tsx+++ b/studio/pages/new/[slug].tsx@@ -193,6 +193,8 @@ export const Wizard = observer(() => {}}+ console.log('PRICING_TIER_LABELS', PRICING_TIER_LABELS)+return (<WizardLayout organization={currentOrg} project={null}><Panel@@ -204,11 +206,11 @@ export const Wizard = observer(() => {</div>}footer={- <div key="panel-footer" className="flex items-center w-full justify-between">+ <div key="panel-footer" className="flex w-full items-center justify-between"><Button type="default" onClick={() => Router.push('/')}>Cancel</Button>- <div className="space-x-3 items-center">+ <div className="items-center space-x-3"><span className="text-scale-900 text-xs">You can rename your project later</span><ButtononClick={onClickNext}@@ -231,7 +233,7 @@ export const Wizard = observer(() => {</p></Panel.Content>- <Panel.Content className="Form section-block--body has-inputs-centered border-b border-t border-panel-border-interior-light dark:border-panel-border-interior-dark space-y-4">+ <Panel.Content className="Form section-block--body has-inputs-centered border-panel-border-interior-light dark:border-panel-border-interior-dark space-y-4 border-b border-t">{organizations.length > 0 && (<Listboxlabel="Organization"@@ -257,7 +259,7 @@ export const Wizard = observer(() => {{canCreateProject && (<>- <Panel.Content className="Form section-block--body has-inputs-centered border-b border-t border-panel-border-interior-light dark:border-panel-border-interior-dark">+ <Panel.Content className="Form section-block--body has-inputs-centered border-panel-border-interior-light dark:border-panel-border-interior-dark border-b border-t"><Inputid="project-name"layout="horizontal"@@ -270,7 +272,7 @@ export const Wizard = observer(() => {/></Panel.Content>- <Panel.Content className="Form section-block--body has-inputs-centered border-b border-panel-border-interior-light dark:border-panel-border-interior-dark">+ <Panel.Content className="Form section-block--body has-inputs-centered border-panel-border-interior-light dark:border-panel-border-interior-dark border-b"><Inputid="password"layout="horizontal"@@ -290,7 +292,7 @@ export const Wizard = observer(() => {/></Panel.Content>- <Panel.Content className="Form section-block--body has-inputs-centered border-b border-panel-border-interior-light dark:border-panel-border-interior-dark">+ <Panel.Content className="Form section-block--body has-inputs-centered border-panel-border-interior-light dark:border-panel-border-interior-dark border-b"><Listboxlayout="horizontal"label="Region"@@ -359,7 +361,7 @@ export const Wizard = observer(() => {{subscriptionStats.isLoading && (<Panel.Content>- <div className="py-10 flex items-center justify-center">+ <div className="flex items-center justify-center py-10"><IconLoader size={16} className="animate-spin" /></div></Panel.Content>diff --git a/studio/pages/project/[ref]/auth/AuthFormSchema.json b/studio/pages/project/[ref]/auth/AuthFormSchema.jsonnew file mode 100644index 00000000000..faf00278cc5--- /dev/null+++ b/studio/pages/project/[ref]/auth/AuthFormSchema.json@@ -0,0 +1,281 @@+[+ {+ "name": "Email",+ "icon": "email-icon",+ "form": [+ {+ "type": "text",+ "name": "email-app-id",+ "label": "email App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "email-id-key",+ "label": "email client ID",+ "description": ""+ },+ {+ "type": "text",+ "name": "email-id-key",+ "label": "email client ID",+ "description": ""+ },+ {+ "type": "text",+ "name": "email-id-key",+ "label": "email client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Phone",+ "icon": "phone-icon",+ "form": [+ {+ "type": "select",+ "name": "phone-app-provider",+ "label": "Phone service provider",+ "description": "You can use a provider etc etc"+ },+ {+ "type": "text",+ "name": "phone-id-key",+ "label": "phone client ID",+ "description": ""+ },+ {+ "type": "text",+ "name": "phone-id-key",+ "label": "phone client ID",+ "description": ""+ },+ {+ "type": "text",+ "name": "phone-id-key",+ "label": "phone client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Google",+ "icon": "google-icon",+ "form": [+ {+ "type": "text",+ "name": "google-app-id",+ "label": "Google App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "google-id-key",+ "label": "Google client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Facebook",+ "icon": "facebook-icon",+ "form": [+ {+ "type": "text",+ "name": "facebook-app-id",+ "label": "Facebook App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "facebook-id-key",+ "label": "Facebook client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Twitter",+ "icon": "twitter-icon",+ "form": [+ {+ "type": "text",+ "name": "twitter-app-id",+ "label": "Twitter App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "twitter-id-key",+ "label": "Twitter client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Apple",+ "icon": "apple-icon",+ "form": [+ {+ "type": "text",+ "name": "apple-app-id",+ "label": "Apple App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "apple-id-key",+ "label": "Apple client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Microsoft",+ "icon": "microsoft-icon",+ "form": [+ {+ "type": "text",+ "name": "microsoft-app-id",+ "label": "Microsoft App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "microsoft-id-key",+ "label": "Microsoft client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Gitlab",+ "icon": "gitlab-icon",+ "form": [+ {+ "type": "text",+ "name": "gitlab-app-id",+ "label": "Gitlab App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "gitlab-id-key",+ "label": "Gitlab client ID",+ "description": ""+ }+ ]+ },++ {+ "name": "Bitbucket",+ "icon": "bitbucket-icon",+ "form": [+ {+ "type": "text",+ "name": "bitbucket-app-id",+ "label": "Bitbucket App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "bitbucket-id-key",+ "label": "Bitbucket client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Discord",+ "icon": "discord-icon",+ "form": [+ {+ "type": "text",+ "name": "discord-app-id",+ "label": "Discord App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "discord-id-key",+ "label": "Discord client ID",+ "description": ""+ }+ ]+ },++ {+ "name": "Github",+ "icon": "github-icon-dark",+ "form": [+ {+ "type": "text",+ "name": "github-app-id",+ "label": "Github App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "github-id-key",+ "label": "Github client ID",+ "description": ""+ }+ ]+ },++ {+ "name": "Slack",+ "icon": "slack-icon",+ "form": [+ {+ "type": "text",+ "name": "slack-app-id",+ "label": "Slack App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "slack-id-key",+ "label": "Slack client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Spotify",+ "icon": "spotify-icon",+ "form": [+ {+ "type": "text",+ "name": "spotify-app-id",+ "label": "Spotify App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "spotify-id-key",+ "label": "Spotify client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Twitch",+ "icon": "twitch-icon",+ "form": [+ {+ "type": "text",+ "name": "twitch-app-id",+ "label": "Twitch App Id",+ "description": ""+ },+ {+ "type": "text",+ "name": "twitch-id-key",+ "label": "Twitch client ID",+ "description": ""+ }+ ]+ }+]diff --git a/studio/pages/project/[ref]/auth/PhoneProvidersSchema.json b/studio/pages/project/[ref]/auth/PhoneProvidersSchema.jsonnew file mode 100644index 00000000000..eb38715495a--- /dev/null+++ b/studio/pages/project/[ref]/auth/PhoneProvidersSchema.json@@ -0,0 +1,36 @@+ {+ "name": "Twilio",+ "icon": "twilio-icon",+ "form": [+ {+ "type": "text",+ "name": "twilio-app-id",+ "label": "Enable twilio Provider",+ "description": ""+ },+ {+ "type": "text",+ "name": "twilio-id-key",+ "label": "twilio client ID",+ "description": ""+ }+ ]+ },+ {+ "name": "Messagebird",+ "icon": "messagebird-icon",+ "form": [+ {+ "type": "text",+ "name": "messagebird-app-id",+ "label": "Enable gitlab messagebird",+ "description": ""+ },+ {+ "type": "text",+ "name": "messagebird-id-key",+ "label": "messagebird client ID",+ "description": ""+ }+ ]+ }\ No newline at end of filediff --git a/studio/pages/project/[ref]/auth/settings-new-all.tsx b/studio/pages/project/[ref]/auth/settings-new-all.tsxnew file mode 100644index 00000000000..b2f58aee8c4--- /dev/null+++ b/studio/pages/project/[ref]/auth/settings-new-all.tsx@@ -0,0 +1,1109 @@+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/ui/Forms/AutoSchemaForm'+import { withAuth } from 'hooks'+import { observer } from 'mobx-react-lite'+import React, { useReducer, useState } from 'react'+import AuthFormSchema from './AuthFormSchema.json'++// 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 AuthForm = () => {+ const [providersFormState, dispatchProvidersForm] = useReducer(providersReducer, initialState)++ console.log('providersFormState from useState', providersFormState)++ // panel+ const Panel = ({+ children,+ header,+ footer,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ footer?: React.ReactNode+ }) => (+ <div className="bg-scale-300 border-scale-400 mx-auto my-8 w-3/4 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>+ )++ const CollapsibleContainer = ({+ children,+ header,+ }: {+ children: React.ReactNode+ header?: React.ReactNode+ }) => {+ return (+ <div+ className="+ bg-scale-400 border-scale-500 hover:border-scale-700 hover:bg-scale-500 mx-auto overflow-hidden+ border shadow+ transition first:rounded-tr+ first:rounded-tl+ last:rounded-br+ last:rounded-bl+ "+ >+ {children}+ </div>+ )+ }++ type formObj = {+ type: string+ name: string+ label: string+ description: string+ }++ interface Provider {+ name: string+ icon: string+ form: formObj[]+ }++ const ProviderForm = ({ provider }: { provider: Provider }) => {+ const [open, setOpen] = useState(false)+ const [active, setActive] = useState(+ providersFormState[`${provider.name.toLowerCase()}-active`]+ )++ console.log('panel active state', active)++ return (+ // <CollapsibleContainer>+ <Collapsible+ open={open}+ onOpenChange={setOpen}+ className="+ bg-scale-100 dark:bg-scale-300+ hover:bg-scale-200 dark:hover:bg-scale-500+ data-open:bg-scale-200 dark:data-open:bg-scale-500+ border-scale-300+ dark:border-scale-500 hover:border-scale-500+ dark:hover:border-scale-700 data-open:border-scale-700++ data-open:pb-px col-span-12 mx-auto+ -space-y-px overflow-hidden+ border shadow++ transition+ first:rounded-tr++ first:rounded-tl+ last:rounded-br last:rounded-bl+ hover:z-50+ "+ >+ <Collapsible.Trigger asChild>+ <button+ type="button"+ className="++ text-scale-1200 group+ flex+ w-full items-center justify-between rounded p-3 px-6"+ >+ <div className="flex items-center gap-3">+ <IconChevronUp+ className="text-scale-800 data-open-parent:rotate-0 data-closed-parent:rotate-180 transition"+ strokeWidth={2}+ />++ <img+ className="w-6 fill-red-400"+ src={`/icons/${provider.icon}.svg`}+ width={21}+ alt={`${provider.name} auth icon`}+ />++ <span className="text-base">{provider.name}</span>+ </div>+ <div className="flex items-center gap-3">+ {active ? (+ <div className="bg-brand-200 border-brand-700 text-brand-900 flex items-center gap-1 rounded-full border py-1 px-1 text-xs">+ <span className="bg-brand-900 text-brand-200 rounded-full p-0.5 text-xs">+ <IconCheck strokeWidth={2} size={12} />+ </span>+ <span className="px-1">Enabled</span>+ </div>+ ) : (+ <div className="bg-scale-100 dark:bg-scale-300 border-scale-500 dark:border-scale-700 text-scale-900 rounded-md border py-1 px-3 text-xs">+ Disabled+ </div>+ )}+ </div>+ </button>+ </Collapsible.Trigger>+ <Form+ name={`provider-${provider.name}-form`}+ initialValues={{+ [`${provider.name.toLowerCase()}-active`]:+ providersFormState[`${provider.name.toLowerCase()}-active`] ||+ // empty form should have this as enabled for UX+ true,+ [`${provider.name.toLowerCase()}-app-id`]:+ providersFormState[`${provider.name.toLowerCase()}-app-id`],+ [`${provider.name.toLowerCase()}-id-key`]:+ providersFormState[`${provider.name.toLowerCase()}-id-key`],+ }}+ validate={(values) => {+ const errors: any = {}++ console.log('validation values', values)++ const input_active = `${provider.name.toLowerCase()}-active`+ const input_app_id = `${provider.name.toLowerCase()}-app-id`+ const input_id_key = `${provider.name.toLowerCase()}-id-key`++ if (values[input_app_id] && values[input_app_id].length < 10)+ errors[input_app_id] = 'App ID must be at least 10 characters long'+ if (values[input_app_id] && values[input_id_key].length < 10)+ errors[input_id_key] = 'Secret must be at least 10 characters long'++ if (values[input_active]) {+ if (!values[input_app_id])+ errors[input_app_id] =+ 'You need to input an application ID if you want to enable this provider.'+ if (!values[input_id_key])+ errors[input_id_key] =+ 'You need to input an application secret if you want to enable this provider.'+ }++ return errors+ }}+ onSubmit={(values: any, { setSubmitting }: any) => {+ setTimeout(() => {+ // alert(JSON.stringify(values, null, 2))+ dispatchProvidersForm({ type: 'update', values: values })+ setActive(values[`${provider.name.toLowerCase()}-active`])+ setSubmitting(false)+ setOpen(false)+ }, 400)+ }}+ >+ {({ isSubmitting, handleReset }: any) => (+ <Collapsible.Content>+ <div+ className="+ bg-scale-100 dark:bg-scale-300+ text-scale-1200 border-scale-500 group border-t py-6 px-6+ "+ >+ <div className="mx-auto max-w-md space-y-6">+ <Toggle+ id={`${provider.name.toLowerCase()}-active`}+ name={`${provider.name.toLowerCase()}-active`}+ label={`Enable ${provider.name} Provider`}+ layout="flex"+ />+ <div className="border-scale-400 border-t"></div>+ {provider.form.map((x) => {+ return (+ <Input+ id={x.name}+ key={x.name}+ name={x.name}+ label={x.label}+ descriptionText={x.description}+ layout="vertical"+ />+ )+ })}+ <div className="border-scale-400 border-t"></div>+ <div className="flex items-center justify-end gap-3">+ <Button+ htmlType="reset"+ onClick={() => {+ handleReset()+ setOpen(false)+ }}+ type="secondary"+ >+ Cancel+ </Button>+ <Button htmlType="submit" loading={isSubmitting}>+ Save+ </Button>+ </div>+ </div>+ </div>+ </Collapsible.Content>+ )}+ </Form>+ </Collapsible>+ // </CollapsibleContainer>+ )+ }++ return (+ <div className="mx-auto my-8">+ <div className="-space-y-px">+ {AuthFormSchema.map((provider: Provider) => {+ return <ProviderForm provider={provider} />+ })}+ </div>+ </div>+ )+}++// type to do later..+let domainInitialState: any = ['https://summersmuir.com', 'http://localhost:3000']++// AuthFormSchema.map((provider) => {+// domainInitialState[`${provider.name.toLowerCase()}-active`] =+// provider.name == 'Email' ? true : false+// domainInitialState[`${provider.name.toLowerCase()}-app-id`] = ''+// domainInitialState[`${provider.name.toLowerCase()}-id-key`] = ''+// })++console.log('form domainInitialState', domainInitialState)++// function domainsReducer(state, action) {+// switch (action.type) {+// case 'update':+// let _state = []+// _state.push(...state)+// _state.push(action.values.domain)+// console.log('new state', _state)+// return _state+// // case 'remove':+// // _state.push(...state)+// // _state = _state.filter((e: any) => e !== action.values)+// // console.log('new state', _state)+// // return _state+// // case 'decrement':+// // return { count: state.count - 1 }+// default:+// throw new Error()+// }+// }++function domainsReducer(state, action) {+ let _state = []+ switch (action.type) {+ case 'update':+ _state.push(...state)+ _state.push(action.values.domain)+ console.log('new state', _state)+ return _state+ case 'remove':+ _state.push(...state)+ _state = _state.filter((e: any) => e !== action.values)+ console.log('new state', _state)+ return _state+ // case 'decrement':+ // return { count: state.count - 1 }+ default:+ throw new Error()+ }+}++const DomainsForm = () => {+ const [domainsFormState, dispatchDomainsForm] = useReducer(domainsReducer, domainInitialState)++ const [deleteOpen, setDeleteOpen] = useState(false)+ const [deleteLoading, setDeleteLoading] = useState(false)+ const [selectedDomain, setSelected] = useState('')++ console.log('domainsFormState from useState', domainsFormState)++ type formObj = {+ type: string+ name: string+ label: string+ description: string+ }++ interface Provider {+ name: string+ icon: string+ form: formObj[]+ }++ const DomainsForm = () => {+ // const [active, setActive] = useState(+ // domainsFormState[`${provider.name.toLowerCase()}-active`]+ // )+ const [open, setOpen] = useState(false)++ // console.log('panel active state', active)++ return (+ <>+ <div className="my-6 flex items-center justify-between">+ <div>+ <h3 className="text-scale-1200 mb-2 text-2xl">Authorised domains</h3>+ <p className="text-scale-900 text-sm">+ Turn payment methods on and off in one click – no engineering time required.+ </p>+ <p className="text-scale-900 text-sm">+ Use our guide to check which payment methods are compatible with your integration.+ </p>+ </div>+ <Button onClick={() => setOpen(true)}>Add domain</Button>+ <Modal+ size="small"+ visible={open}+ onCancel={() => setOpen(!open)}+ header={+ <div className="text-scale-1200 flex items-center gap-2">+ <div className="flex items-baseline gap-2">+ <h3 className="text-sm">Add a new domain</h3>+ </div>+ </div>+ }+ contentStyle={{ padding: 0 }}+ hideFooter+ >+ <Form+ id="new-domain-form"+ initialValues={{+ domain: '',+ }}+ validateOnBlur+ onSubmit={(values: any, { setSubmitting }: any) => {+ console.log('submitting domain')+ setTimeout(() => {+ setSubmitting(false)+ dispatchDomainsForm({ type: 'update', values: values })+ setOpen(false)+ }, 400)+ }}+ validate={(values) => {+ const errors: any = {}+ if (!values.domain) {+ errors.domain = 'A domain is required'+ } else if (+ !/^((https?|ftp|smtp):\/\/)?(www.)?[a-z0-9]+\.[a-z]+(\/[a-zA-Z0-9#]+\/?)*$/i.test(+ values.domain+ )+ ) {+ errors.domain = 'Not a valid URL. Please use http:// or https://'+ }+ return errors+ }}+ >+ {({ isSubmitting, errors, touched }: any) => {+ // console.log('errors in form', errors)+ // console.log('touched in form', touched)+ return (+ <div className="mb-4 space-y-4 pt-4">+ <div className="px-5">+ <p className="text-scale-1100 text-sm">+ This will add a domain to a list of allowed domains that can interact with+ your Authenticaton services for this project.+ </p>+ </div>+ <div className="border-overlay-border border-t"></div>+ <div className="px-5">+ <Input+ id="domain"+ name="domain"+ label="Domain"+ placeholder="https://mydomain.com"+ />+ </div>+ <div className="border-overlay-border border-t"></div>+ <div className="px-5">+ <Button+ form="new-domain-form"+ htmlType="submit"+ block+ size="medium"+ loading={isSubmitting}+ >+ Add domain+ </Button>+ </div>+ </div>+ )+ }}+ </Form>+ </Modal>+ </div>+ </>+ )+ }++ console.log('RENDER DOMAINS')++ return (+ <div className="mx-auto my-8">+ <DomainsForm />+ <div className="-space-y-px">+ {domainsFormState.map((domain) => {+ return (+ <>+ <div+ className="bg-scale-300 border-scale-500 text-scale-1200 flex items-center+ justify-between gap-2+ border px-6+ py-4 text-sm+ first:rounded-tr first:rounded-tl last:rounded-br last:rounded-bl+ "+ >+ <div className="flex items-center gap-2 font-mono">+ <span className="text-scale-900">+ <IconGlobe strokeWidth={2} size={14} />+ </span>+ {domain}+ </div>+ <Button+ type="default"+ icon={<IconTrash />}+ onClick={() => {+ setSelected(domain)+ setDeleteOpen(true)+ }}+ >+ Remove+ </Button>+ </div>+ </>+ )+ })}+ </div>+ <Modal+ size="small"+ visible={deleteOpen}+ onCancel={() => setDeleteOpen(!open)}+ header={+ <div className="text-scale-1200 flex items-center gap-2">+ <div className="flex items-baseline gap-2">+ <h3 className="text-sm">Remove domain</h3>+ </div>+ </div>+ }+ contentStyle={{ padding: 0 }}+ hideFooter+ >+ <div className="mb-4 space-y-4 pt-4">+ <div className="px-5">+ <p className="text-scale-1100 mb-2 text-sm">+ Are you sure you want to remove{' '}+ <span className="text-scale-1200">{selectedDomain}</span>?+ </p>+ <p className="text-scale-900 text-sm">+ This domain will no longer work with your Authentication configuration.+ </p>+ </div>+ <div className="border-overlay-border border-t"></div>+ <div className="flex gap-3 px-5">+ <Button+ type="secondary"+ block+ size="medium"+ onClick={() => {+ // setOpen(!open)+ }}+ >+ Cancel+ </Button>+ <Button+ block+ size="medium"+ type="warning"+ loading={deleteLoading}+ onClick={() => {+ setDeleteLoading(true)+ setTimeout(() => {+ dispatchDomainsForm({+ type: 'remove',+ values: selectedDomain,+ })+ setDeleteOpen(!deleteOpen)+ setDeleteLoading(false)+ }, 800)+ }}+ >+ {deleteLoading ? 'Removing...' : 'Remove domain'}+ </Button>+ </div>+ </div>+ </Modal>+ </div>+ )+}++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">Sign-in method</h1>+ </div>+ <div className="border-scale-400 border-t"></div>+ <div>+ <h3 className="text-scale-1200 mb-2 text-2xl">General settings</h3>+ <p className="text-scale-900 text-sm">+ Turn payment methods on and off in one click – no engineering time required.+ </p>+ <p className="text-scale-900 text-sm">+ Use our guide to check which payment methods are compatible with your integration.+ </p>+ <CardForm />+ </div>+ <div>+ <h3 className="text-scale-1200 mb-2 text-2xl">Providers</h3>+ <p className="text-scale-900 text-sm">+ Turn payment methods on and off in one click – no engineering time required.+ </p>+ <p className="text-scale-900 text-sm">+ Use our guide to check which payment methods are compatible with your integration.+ </p>+ <AuthForm />+ </div>++ <DomainsForm />+ </div>+ </div>+ )+}++export default withAuth(observer(Auth))diff --git a/studio/pages/project/[ref]/auth/settings-new.tsx b/studio/pages/project/[ref]/auth/settings-new.tsxnew file mode 100644index 00000000000..eb083c4739c--- /dev/null+++ b/studio/pages/project/[ref]/auth/settings-new.tsx@@ -0,0 +1,53 @@+import {+ Button,+ Collapsible,+ Form,+ IconArrowRight,+ IconCheck,+ IconChevronUp,+ IconGlobe,+ IconTrash,+ IconX,+ Input,+ InputNumber,+ Modal,+ Tabs,+ Toggle,+} from '@supabase/ui'+import { AuthLayout } from 'components/layouts'++import { withAuth } from 'hooks'+import { observer } from 'mobx-react-lite'+import React, { useReducer, useState } from 'react'+// import AuthFormSchema from './AuthFormSchema.json'++import { AutoSchemaForm } from 'components/ui/Forms'++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>+ <h3 className="text-scale-1200 mb-2 text-2xl">General settings</h3>+ <p className="text-scale-900 text-sm">+ Turn payment methods on and off in one click – no engineering time required.+ </p>+ <p className="text-scale-900 text-sm">+ Use our guide to check which payment methods are compatible with your integration.+ </p>+ <AutoSchemaForm />+ </div>+ </div>+ )+}++export default withAuth(observer(Auth))diff --git a/studio/pages/project/[ref]/auth/templates-new.tsx b/studio/pages/project/[ref]/auth/templates-new.tsxnew file mode 100644index 00000000000..c35d82c6bc5--- /dev/null+++ b/studio/pages/project/[ref]/auth/templates-new.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/ui/Forms/AutoSchemaForm'+import { withAuth } from 'hooks'+import { observer } from 'mobx-react-lite'+import React, { useReducer, useState } from 'react'+import AuthFormSchema from './AuthFormSchema.json'++// 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))