The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
adds reset password form and toasts
Alaister Young6db7f5ada815
diff --git a/studio/components/interfaces/Login/ForgotPasswordForm.tsx b/studio/components/interfaces/Login/ForgotPasswordForm.tsxindex 272cdb60671..770c356b78b 100644--- a/studio/components/interfaces/Login/ForgotPasswordForm.tsx+++ b/studio/components/interfaces/Login/ForgotPasswordForm.tsx@@ -1,4 +1,6 @@+import { useStore } from 'hooks'import { auth } from 'lib/gotrue'+import { useRouter } from 'next/router'import { Button, Form, Input } from 'ui'import { object, string } from 'yup'@@ -7,16 +9,39 @@ const forgotPasswordSchema = object({})const ForgotPasswordForm = () => {+ const { ui } = useStore()+ const router = useRouter()+const onForgotPassword = async ({ email }: { email: string }) => {- const result = await auth.resetPasswordForEmail(email)- console.log('result:', result)+ const toastId = ui.setNotification({+ category: 'loading',+ message: `Sending password reset email...`,+ })++ const { error } = await auth.resetPasswordForEmail(email)++ if (!error) {+ ui.setNotification({+ id: toastId,+ category: 'success',+ message: `Password reset email sent successfully!`,+ })++ await router.push('/')+ } else {+ ui.setNotification({+ id: toastId,+ category: 'error',+ message: error.message,+ })+ }}return (<FormvalidateOnBlurid="forgot-password-form"- initialValues={{ email: '', password: '' }}+ initialValues={{ email: '' }}validationSchema={forgotPasswordSchema}onSubmit={onForgotPassword}>diff --git a/studio/components/interfaces/Login/LoginForm.tsx b/studio/components/interfaces/Login/LoginForm.tsxindex 39dcbd416bd..f3adae920b4 100644--- a/studio/components/interfaces/Login/LoginForm.tsx+++ b/studio/components/interfaces/Login/LoginForm.tsx@@ -1,4 +1,7 @@+import { useStore } from 'hooks'import { auth } from 'lib/gotrue'+import { useRouter } from 'next/router'+import { useSWRConfig } from 'swr'import { Button, Form, Input } from 'ui'import { object, string } from 'yup'@@ -8,9 +11,37 @@ const loginSchema = object({})const LoginForm = () => {+ const { ui } = useStore()+ const router = useRouter()+ const { cache } = useSWRConfig()+const onLogin = async ({ email, password }: { email: string; password: string }) => {- const result = await auth.signInWithPassword({ email, password })- console.log('result:', result)+ const toastId = ui.setNotification({+ category: 'loading',+ message: `Logging in...`,+ })++ const { error } = await auth.signInWithPassword({ email, password })++ if (!error) {+ ui.setNotification({+ id: toastId,+ category: 'success',+ message: `Logged in successfully!`,+ })++ // .clear() does actually exist on the cache object, but it's not in the types 🤦🏻+ // @ts-ignore+ cache.clear()++ await router.push('/projects')+ } else {+ ui.setNotification({+ id: toastId,+ category: 'error',+ message: error.message,+ })+ }}return (diff --git a/studio/components/interfaces/Login/RegisterForm.tsx b/studio/components/interfaces/Login/RegisterForm.tsxindex bff2d69c502..cc26ff3c1a8 100644--- a/studio/components/interfaces/Login/RegisterForm.tsx+++ b/studio/components/interfaces/Login/RegisterForm.tsx@@ -1,5 +1,6 @@+import { useStore } from 'hooks'import { auth } from 'lib/gotrue'-import Link from 'next/link'+import { useRouter } from 'next/router'import { Button, Form, IconLock, Input } from 'ui'import { object, string } from 'yup'@@ -13,10 +14,15 @@ const registerSchema = object({).required('Username is required'),email: string().email('Must be a valid email').required('Email is required'),- password: string().required('Password is required'),+ password: string()+ .required('Password is required')+ .min(8, 'Password must be at least 8 characters long'),})const RegisterForm = () => {+ const { ui } = useStore()+ const router = useRouter()+const onRegister = async ({username,email,@@ -26,8 +32,28 @@ const RegisterForm = () => {email: stringpassword: string}) => {- const result = await auth.signUp({ email, password, options: { data: { username } } })- console.log('result:', result)+ const toastId = ui.setNotification({+ category: 'loading',+ message: `Registering...`,+ })++ const { error } = await auth.signUp({ email, password, options: { data: { username } } })++ if (!error) {+ ui.setNotification({+ id: toastId,+ category: 'success',+ message: `Logged in successfully!`,+ })++ await router.push('/projects')+ } else {+ ui.setNotification({+ id: toastId,+ category: 'error',+ message: error.message,+ })+ }}return (diff --git a/studio/components/interfaces/Login/ResetPasswordForm.tsx b/studio/components/interfaces/Login/ResetPasswordForm.tsxindex 5b34602b0f5..335ddfd6206 100644--- a/studio/components/interfaces/Login/ResetPasswordForm.tsx+++ b/studio/components/interfaces/Login/ResetPasswordForm.tsx@@ -1,5 +1,80 @@+import { useStore } from 'hooks'+import { auth } from 'lib/gotrue'+import { useRouter } from 'next/router'+import { Button, Form, Input } from 'ui'+import { object, string } from 'yup'++const resetPasswordSchema = object({+ password: string()+ .required('Password is required')+ .min(8, 'Password must be at least 8 characters long'),+})+const ResetPasswordForm = () => {- return <div></div>+ const { ui } = useStore()+ const router = useRouter()++ const onResetPassword = async ({ password }: { password: string }) => {+ const toastId = ui.setNotification({+ category: 'loading',+ message: `Saving password...`,+ })++ const { error } = await auth.updateUser({ password })++ if (!error) {+ ui.setNotification({+ id: toastId,+ category: 'success',+ message: `Password saved successfully!`,+ })++ await router.push('/projects')+ } else {+ ui.setNotification({+ id: toastId,+ category: 'error',+ message: error.message,+ })+ }+ }++ return (+ <Form+ validateOnBlur+ id="reset-password-form"+ initialValues={{ password: '' }}+ validationSchema={resetPasswordSchema}+ onSubmit={onResetPassword}+ >+ {({ isSubmitting }: { isSubmitting: boolean }) => {+ return (+ <div className="mb-4 space-y-4 pt-4">+ <Input+ id="password"+ name="password"+ type="password"+ label="Password"+ placeholder="••••••••"+ />++ <div className="border-overlay-border border-t" />++ <Button+ block+ form="reset-password-form"+ htmlType="submit"+ size="medium"+ disabled={isSubmitting}+ loading={isSubmitting}+ >+ Save New Password+ </Button>+ </div>+ )+ }}+ </Form>+ )}export default ResetPasswordFormdiff --git a/studio/components/layouts/LoginLayout/LoginLayout.tsx b/studio/components/layouts/LoginLayout/LoginLayout.tsxindex 25f1cf7aa1d..642ed3c935d 100644--- a/studio/components/layouts/LoginLayout/LoginLayout.tsx+++ b/studio/components/layouts/LoginLayout/LoginLayout.tsx@@ -7,11 +7,13 @@ import { PropsWithChildren } from 'react'type LoginLayoutProps = {title: stringshowDisclaimer?: boolean+ logoLinkToMarketingSite?: boolean}const LoginLayout = ({title,showDisclaimer = true,+ logoLinkToMarketingSite = false,children,}: PropsWithChildren<LoginLayoutProps>) => {const {@@ -24,14 +26,16 @@ const LoginLayout = ({<nav className="relative flex items-center justify-between sm:h-10"><div className="flex flex-shrink-0 flex-grow items-center lg:flex-grow-0"><div className="flex w-full items-center justify-between md:w-auto">- <a href="https://supabase.com">- <Image- src={theme == 'dark' ? '/img/supabase-dark.svg' : '/img/supabase-light.svg'}- alt=""- height={24}- width={120}- />- </a>+ <Link href={logoLinkToMarketingSite ? 'https://supabase.com' : '/'}>+ <a>+ <Image+ src={theme == 'dark' ? '/img/supabase-dark.svg' : '/img/supabase-light.svg'}+ alt=""+ height={24}+ width={120}+ />+ </a>+ </Link></div></div>diff --git a/studio/pages/index.tsx b/studio/pages/index.tsxindex 7599420efda..1389249c596 100644--- a/studio/pages/index.tsx+++ b/studio/pages/index.tsx@@ -50,7 +50,11 @@ const LoginPage: NextPageWithLayout = () => {)}-LoginPage.getLayout = (page) => <LoginLayout title="Login">{page}</LoginLayout>+LoginPage.getLayout = (page) => (+ <LoginLayout title="Login" logoLinkToMarketingSite={true}>+ {page}+ </LoginLayout>+)export default LoginPagediff --git a/studio/pages/reset-password.tsx b/studio/pages/reset-password.tsxindex 80827264acf..af8584e1cb5 100644--- a/studio/pages/reset-password.tsx+++ b/studio/pages/reset-password.tsx@@ -1,5 +1,31 @@-const ResetPasswordPage = () => {- return <div></div>+import ResetPasswordForm from 'components/interfaces/Login/ResetPasswordForm'+import { LoginLayout } from 'components/layouts'+import Link from 'next/link'+import { NextPageWithLayout } from 'types'++const ResetPasswordPage: NextPageWithLayout = () => {+ return (+ <>+ <div className="flex flex-col gap-4">+ <ResetPasswordForm />+ </div>++ <div className="w-full border-t border-scale-700 my-4" />++ <div className="mb-4">+ <span className="text-scale-1000">Already have an account?</span>{' '}+ <Link href="/">+ <a className="underline hover:text-scale-1100">Login</a>+ </Link>+ </div>+ </>+ )}+ResetPasswordPage.getLayout = (page) => (+ <LoginLayout title="Reset Password" showDisclaimer={false}>+ {page}+ </LoginLayout>+)+export default ResetPasswordPage