The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Address all comments from the PR.
Ivan Vasilovb84aa9254a3e
diff --git a/studio/components/interfaces/Account/AddNewFactorModal.tsx b/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsxsimilarity index 100%rename from studio/components/interfaces/Account/AddNewFactorModal.tsxrename to studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsxdiff --git a/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx b/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsxnew file mode 100644index 00000000000..3ef292cc066--- /dev/null+++ b/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx@@ -0,0 +1,86 @@+import ConfirmationModal from 'components/ui/ConfirmationModal'+import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'+import { useStore } from 'hooks'+import {+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ IconAlertTriangle,+ Modal,+} from 'ui'++export const DeleteFactorModal = ({+ factorId,+ lastFactorToBeDeleted,+ onClose,+}: {+ factorId: string+ lastFactorToBeDeleted: boolean+ onClose: () => void+}) => {+ const { ui } = useStore()++ const { mutate: unenroll, isLoading } = useMfaUnenrollMutation({+ onError: (error) => {+ ui.setNotification({+ category: 'error',+ message: `Failed to delete a second factor authentication: ${error?.message}`,+ })+ },+ onSuccess: () => {+ ui.setNotification({+ category: 'success',+ message: `Successfully deleted a second factor authentication.`,+ })+ onClose()+ },+ })++ return (+ <ConfirmationModal+ size="medium"+ visible+ danger+ header="Confirm to delete factor"+ buttonLabel="Delete"+ buttonLoadingLabel="Deleting"+ loading={isLoading}+ onSelectCancel={onClose}+ onSelectConfirm={() => {+ unenroll({ factorId })+ }}+ >+ <Modal.Content className="py-6">+ <Alert_Shadcn_ variant="warning">+ <IconAlertTriangle strokeWidth={2} />+ <AlertTitle_Shadcn_>+ {lastFactorToBeDeleted+ ? 'Multi-factor authentication will be disabled'+ : 'This action cannot be undone'}+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ {lastFactorToBeDeleted+ ? 'There are no other factors that are set up once you delete this factor, as such your account will no longer be guarded by multi-factor authentication'+ : 'You will no longer be able to use this authenticator app for multi-factor authentication when signing in to the dashboard'}+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ <div className="text-sm px-1 pt-4">+ <span className="font-bold">Before deleting this factor, consider:</span>+ <ul className="text-scale-900 py-1 list-disc mx-4 space-y-1">+ {lastFactorToBeDeleted ? (+ <>+ <li>Adding another authenticator app as a factor prior to deleting</li>+ <li>Ensure that your account does not need multi-factor authentication</li>+ </>+ ) : (+ <>+ <li>Your backup authenticator app is still available to use</li>+ <li>Adding another authenticator app thereafter as a backup</li>+ </>+ )}+ </ul>+ </div>+ </Modal.Content>+ </ConfirmationModal>+ )+}diff --git a/studio/components/interfaces/Account/TOTPFactors/index.tsx b/studio/components/interfaces/Account/TOTPFactors/index.tsxnew file mode 100644index 00000000000..4a8f731cf8f--- /dev/null+++ b/studio/components/interfaces/Account/TOTPFactors/index.tsx@@ -0,0 +1,103 @@+import AlertError from 'components/ui/AlertError'+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'+import { useMfaListFactorsQuery } from 'data/profile/mfa-list-factors-query'+import dayjs from 'dayjs'+import { DATETIME_FORMAT } from 'lib/constants'+import { useState } from 'react'+import {+ AlertDescription_Shadcn_,+ AlertTitle_Shadcn_,+ Alert_Shadcn_,+ Button,+ IconAlertCircle,+ IconTrash,+} from 'ui'+import AddNewFactorModal from './AddNewFactorModal'+import { DeleteFactorModal } from './DeleteFactorModal'++const TOTPFactors = () => {+ const [isAddNewFactorOpen, setIsAddNewFactorOpen] = useState(false)+ const [factorToBeDeleted, setFactorToBeDeleted] = useState<string | null>(null)+ const { data, isLoading, isError, isSuccess, error } = useMfaListFactorsQuery()++ return (+ <>+ <section>+ <span className="text-sm prose color-slate-1000">+ Generate one-time passwords via authenticator apps like 1Password, Authy, etc. as a second+ factor to verify your identity when prompted during sign-in.+ </span>+ <div className="py-2">+ {isLoading && <GenericSkeletonLoader />}+ {isError && (+ <AlertError error={error} subject="Failed to retrieve account security information" />+ )}+ {isSuccess && (+ <>+ {data.totp.length === 1 && (+ <Alert_Shadcn_ variant="default">+ <IconAlertCircle className="h-4 w-4" />+ <AlertTitle_Shadcn_>+ We recommend configuring two authenticator apps across different devices+ </AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_ className="flex flex-col gap-3">+ The two authenticator apps will serve as a backup for each other.+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ )}+ <div className="py-2">+ {data.totp.map((factor) => {+ return (+ <div key={factor.id} className="flex flex-row justify-between py-2">+ <div className="flex flex-col">+ <span className="text-sm text-white">+ Name: {factor.friendly_name ?? 'No name provided'}+ </span>+ <span className="text-sm text-scale-900">Factor ID: {factor.id}</span>+ </div>+ <div className="flex items-center gap-2">+ <span className="text-sm text-scale-900">+ Created at {dayjs(factor.updated_at).format(DATETIME_FORMAT)}+ </span>+ <Button+ size="tiny"+ type="default"+ icon={<IconTrash />}+ onClick={() => setFactorToBeDeleted(factor.id)}+ />+ </div>+ </div>+ )+ })}+ </div>+ {data.totp.length < 2 ? (+ <>+ <div className="pt-2">+ <Button+ size="small"+ onClick={() => {+ setIsAddNewFactorOpen(true)+ }}+ >+ Add new app+ </Button>+ </div>+ </>+ ) : null}+ </>+ )}+ </div>+ </section>+ {isAddNewFactorOpen && <AddNewFactorModal onClose={() => setIsAddNewFactorOpen(false)} />}+ {factorToBeDeleted && (+ <DeleteFactorModal+ factorId={factorToBeDeleted}+ lastFactorToBeDeleted={data?.totp.length === 1}+ onClose={() => setFactorToBeDeleted(null)}+ />+ )}+ </>+ )+}++export default TOTPFactorsdiff --git a/studio/components/interfaces/Account/index.ts b/studio/components/interfaces/Account/index.tsindex 38c906b34f7..4630ecbb9d8 100644--- a/studio/components/interfaces/Account/index.ts+++ b/studio/components/interfaces/Account/index.ts@@ -1,6 +1,6 @@import AccessTokenList from './AccessTokenList'-import AddNewFactorModal from './AddNewFactorModal'import NewAccessTokenButton from './NewAccessTokenButton'import NewTokenBanner from './NewTokenBanner'+import TOTPFactors from './TOTPFactors'-export { AccessTokenList, NewTokenBanner, NewAccessTokenButton, AddNewFactorModal }+export { AccessTokenList, NewTokenBanner, NewAccessTokenButton, TOTPFactors }diff --git a/studio/components/interfaces/SignIn/SignInMfaForm.tsx b/studio/components/interfaces/SignIn/SignInMfaForm.tsxindex 5a1f14e0e81..0b5d4d09a42 100644--- a/studio/components/interfaces/SignIn/SignInMfaForm.tsx+++ b/studio/components/interfaces/SignIn/SignInMfaForm.tsx@@ -21,16 +21,17 @@ const SignInMfaForm = () => {const { mutateAsync: mfaChallengeAndVerify, isLoading } = useMfaChallengeAndVerifyMutation()const [selectedFactor, setSelectedFactor] = useState<Factor | null>(null)- // if the user wanders into this page and he has no MFA setup, send the user to the next screen- if (factorsSuccess && factors.totp.length === 0) {- queryClient.resetQueries().then(() => pushNext())- }-useEffect(() => {if (factorsSuccess) {- setSelectedFactor(factors.totp[0])+ // if the user wanders into this page and he has no MFA setup, send the user to the next screen+ if (factors.totp.length === 0) {+ queryClient.resetQueries().then(() => pushNext())+ }+ if (factors.totp.length > 0) {+ setSelectedFactor(factors.totp[0])+ }}- }, [factors?.totp, factorsSuccess])+ }, [factors?.totp, factorsSuccess, pushNext, queryClient])const onSignIn = async ({ code }: { code: string }) => {const toastId = ui.setNotification({@@ -78,6 +79,7 @@ const SignInMfaForm = () => {id="code"name="code"type="text"+ autoFocusicon={<IconLock />}placeholder="XXXXXX"disabled={isLoading}diff --git a/studio/components/layouts/SignInLayout/SignInLayout.tsx b/studio/components/layouts/SignInLayout/SignInLayout.tsxindex 7a25b11d9d0..8bc879ef557 100644--- a/studio/components/layouts/SignInLayout/SignInLayout.tsx+++ b/studio/components/layouts/SignInLayout/SignInLayout.tsx@@ -3,7 +3,7 @@ import { useTheme } from 'common'import { useFlag } from 'hooks'import { usePushNext } from 'hooks/misc/useAutoAuthRedirect'import { BASE_PATH } from 'lib/constants'-import { auth } from 'lib/gotrue'+import { auth, getAccessToken } from 'lib/gotrue'import { observer } from 'mobx-react-lite'import Image from 'next/image'import Link from 'next/link'@@ -43,14 +43,17 @@ const SignInLayout = ({return}- auth.initialize().then(({ error }) => {- if (error) {- // if there was a problem signing in via the url, don't redirect- return- }+ auth+ .initialize()+ .then(async ({ error }) => {+ if (error) {+ // if there was a problem signing in via the url, don't redirect+ return+ }- auth.getSession().then(async ({ data: { session } }) => {- try {+ const token = await getAccessToken()++ if (token) {const { data, error } = await auth.mfa.getAuthenticatorAssuranceLevel()if (error) {// if there was a problem signing in via the url, don't redirect@@ -58,20 +61,22 @@ const SignInLayout = ({}if (data) {+ // we're already where we need to be+ if (router.pathname === '/sign-in-mfa') {+ return+ }if (data.currentLevel !== data.nextLevel) {router.replace('/sign-in-mfa')return}}- if (session) {- await queryClient.resetQueries()- await pushNext()- }- } catch {}+ await queryClient.resetQueries()+ await pushNext()+ }})- })- }, [])+ .catch(() => {}) // catch all errors thrown by auth methods+ }, [pushNext, queryClient, router])const [quote, setQuote] = useState<{text: stringdiff --git a/studio/lib/constants/index.ts b/studio/lib/constants/index.tsindex 614c67455ad..3a83865cdae 100644--- a/studio/lib/constants/index.ts+++ b/studio/lib/constants/index.ts@@ -10,8 +10,14 @@ export const PG_META_URL = IS_PLATFORM: process.env.STUDIO_PG_META_URLexport const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? ''+/**+ * @deprecated use DATETIME_FORMAT+ */export const DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ssZ'+// should be used for all dayjs formattings shown to the user. Includes timezone info.+export const DATETIME_FORMAT = 'DD MMM YYYY, HH:mm:ss (ZZ)'+// Keyboard Shortcuts Relatedexport const SHORTCUT_KEYS = {VIEW_ALL_SHORTCUTS: 'VIEW_ALL_SHORTCUTS',diff --git a/studio/pages/account/security.tsx b/studio/pages/account/security.tsxindex 18050504d4d..baf312d114c 100644--- a/studio/pages/account/security.tsx+++ b/studio/pages/account/security.tsx@@ -1,27 +1,24 @@-import { AddNewFactorModal } from 'components/interfaces/Account'+import { NextPageWithLayout } from 'types'+import { Badge, cn, Collapsible, IconSmartphone } from 'ui'++import { TOTPFactors } from 'components/interfaces/Account'import { AccountLayout } from 'components/layouts'-import AlertError from 'components/ui/AlertError'-import ConfirmationModal from 'components/ui/ConfirmationModal'import { FormHeader } from 'components/ui/Forms'-import ShimmeringLoader from 'components/ui/ShimmeringLoader'import { useMfaListFactorsQuery } from 'data/profile/mfa-list-factors-query'-import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'-import { useStore } from 'hooks'-import { useState } from 'react'-import { NextPageWithLayout } from 'types'-import {- Accordion,- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Badge,- Button,- IconAlertCircle,- IconAlertTriangle,- IconSmartphone,- IconTrash,- Modal,-} from 'ui'++const collapsibleClasses = [+ '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 rounded',+ '-space-y-px overflow-hidden',+ 'border shadow',+ 'transition',+ 'hover:z-50',+]const Security: NextPageWithLayout = () => {const { data } = useMfaListFactorsQuery()@@ -34,36 +31,30 @@ const Security: NextPageWithLayout = () => {description="Add an additional layer of security to your account by requiring more than just a password to sign in."/></div>- <Accordion- openBehaviour="multiple"- chevronAlign="left"- type="bordered"- className="max-w-4xl"- defaultValue={['auth-app']}- >- <Accordion.Item- header={- <div className="flex flex-row justify-between items-center p-2 w-full">- <div className="flex flex-row gap-2 items-center p-2">- <IconSmartphone />- <span className="text-lg">Authenticator app</span>- </div>-- {data ? (- <>- {data.totp.length === 0 && <Badge color="red">0 apps configured</Badge>}- {data.totp.length === 1 && <Badge color="yellow">1 apps configured</Badge>}- {data.totp.length === 2 && <Badge color="green">2 apps configured</Badge>}- </>- ) : null}+ <Collapsible className={cn(collapsibleClasses)}>+ <Collapsible.Trigger asChild>+ <button+ type="button"+ className="group flex w-full items-center justify-between rounded py-3 px-6 text-scale-1200"+ >+ <div className="flex flex-row gap-2 items-center p-2">+ <IconSmartphone />+ <span className="text-lg">Authenticator app</span></div>- }- id="auth-app"- className="flex flex-row gap-8"- >- <ProfileCard />- </Accordion.Item>- </Accordion>++ {data ? (+ <Badge+ color={data.totp.length === 0 ? 'red' : data.totp.length === 1 ? 'yellow' : 'green'}+ >+ {data.totp.length} apps configured+ </Badge>+ ) : null}+ </button>+ </Collapsible.Trigger>+ <Collapsible.Content className="group border-t border-scale-500 bg-scale-100 py-6 px-6 text-scale-1200 dark:bg-scale-300">+ <TOTPFactors />+ </Collapsible.Content>+ </Collapsible></div>)}@@ -75,172 +66,3 @@ Security.getLayout = (page) => ()export default Security--const ProfileCard = () => {- const [isAddNewFactorOpen, setIsAddNewFactorOpen] = useState(false)- const [factorToBeDeleted, setFactorToBeDeleted] = useState<string | null>(null)- const { data, isLoading, isError, isSuccess, error } = useMfaListFactorsQuery()-- return (- <>- <section className="px-6 pt-4">- <div>- <span className="text-sm prose color-slate-1000">- Generate one-time passwords via authenticator apps like 1Password, Authy, etc. as a- second factor to verify your identity when prompted during sign-in.- </span>- </div>- {isLoading && (- <div className="py-2">- {[1, 2].map((number) => {- return <ShimmeringLoader key={number} />- })}- </div>- )}- {isError && (- <div className="py-4">- <AlertError error={error} subject="Failed to retrieve account security information" />- </div>- )}- {isSuccess && (- <>- {data.totp.length === 1 && (- <Alert_Shadcn_ variant="default" className="mt-2">- <IconAlertCircle className="h-4 w-4" />- <AlertTitle_Shadcn_>- We recommend configuring two authenticator apps across different devices- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_ className="flex flex-col gap-3">- The two authenticator apps will serve as a backup for each other.- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- )}- <div className="py-2">- {data.totp.map((factor) => {- return (- <div key={factor.id} className="flex flex-row justify-between py-2">- <div className="flex flex-col">- <span className="text-sm text-white">- Name: {factor.friendly_name ?? 'No name provided'}- </span>- <span className="text-sm text-scale-900">Factor ID: {factor.id}</span>- </div>- <div className="flex items-center gap-2">- <span className="text-sm text-scale-900">- Created at {new Date(factor.updated_at).toLocaleString()}- </span>- <Button- size="tiny"- type="default"- icon={<IconTrash />}- onClick={() => setFactorToBeDeleted(factor.id)}- />- </div>- </div>- )- })}- </div>- {data.totp.length < 2 ? (- <>- <div className="py-2">- <Button- size="small"- onClick={() => {- setIsAddNewFactorOpen(true)- }}- >- Add new app- </Button>- </div>- </>- ) : null}- </>- )}- </section>- {isAddNewFactorOpen && <AddNewFactorModal onClose={() => setIsAddNewFactorOpen(false)} />}- {factorToBeDeleted && (- <DeleteFactorModal- factorId={factorToBeDeleted}- lastFactorToBeDeleted={data?.totp.length === 1}- onClose={() => setFactorToBeDeleted(null)}- />- )}- </>- )-}--const DeleteFactorModal = ({- factorId,- lastFactorToBeDeleted,- onClose,-}: {- factorId: string- lastFactorToBeDeleted: boolean- onClose: () => void-}) => {- const { ui } = useStore()-- const { mutate: unenroll, isLoading } = useMfaUnenrollMutation({- onError: (error) => {- ui.setNotification({- category: 'error',- message: `Failed to delete a second factor authentication: ${error?.message}`,- })- },- onSuccess: () => {- ui.setNotification({- category: 'success',- message: `Successfully deleted a second factor authentication.`,- })- onClose()- },- })-- return (- <ConfirmationModal- size="medium"- visible- danger- header="Confirm to delete factor"- buttonLabel="Delete"- buttonLoadingLabel="Deleting"- loading={isLoading}- onSelectCancel={onClose}- onSelectConfirm={() => {- unenroll({ factorId })- }}- >- <Modal.Content className="py-6">- <Alert_Shadcn_ variant="warning">- <IconAlertTriangle strokeWidth={2} />- <AlertTitle_Shadcn_>- {lastFactorToBeDeleted- ? 'Multi-factor authentication will be disabled'- : 'This action cannot be undone'}- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- {lastFactorToBeDeleted- ? 'There are no other factors that are set up once you delete this factor, as such your account will no longer be guarded by multi-factor authentication'- : 'You will no longer be able to use this authenticator app for multi-factor authentication when signing in to the dashboard'}- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- <div className="text-sm px-1 pt-4">- <span className="font-bold">Before deleting this factor, consider:</span>- <ul className="text-scale-900 py-1 list-disc mx-4 space-y-1">- {lastFactorToBeDeleted ? (- <>- <li>Adding another authenticator app as a factor prior to deleting</li>- <li>Ensure that your account does not need multi-factor authentication</li>- </>- ) : (- <>- <li>Your backup authenticator app is still available to use</li>- <li>Adding another authenticator app thereafter as a backup</li>- </>- )}- </ul>- </div>- </Modal.Content>- </ConfirmationModal>- )-}diff --git a/studio/pages/sign-in-mfa.tsx b/studio/pages/sign-in-mfa.tsxindex eabad37f83e..cdede888780 100644--- a/studio/pages/sign-in-mfa.tsx+++ b/studio/pages/sign-in-mfa.tsx@@ -4,11 +4,9 @@ import { NextPageWithLayout } from 'types'const SignInMfaPage: NextPageWithLayout = () => {return (- <>- <div className="flex flex-col gap-5">- <SignInMfaForm />- </div>- </>+ <div className="flex flex-col gap-5">+ <SignInMfaForm />+ </div>)}