The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Small style fixes and fix unenrolling when cancelling
Joshen Lim6ab4daa5ace3
diff --git a/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx b/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsxindex 822b59b3b11..db9b8106400 100644--- a/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx+++ b/studio/components/interfaces/Account/TOTPFactors/AddNewFactorModal.tsx@@ -1,3 +1,7 @@+import Image from 'next/image'+import { Dispatch, SetStateAction, useEffect, useState } from 'react'+import { Input, Modal } from 'ui'+import ConfirmationModal from 'components/ui/ConfirmationModal'import InformationBox from 'components/ui/InformationBox'import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'@@ -5,18 +9,19 @@ import { useMfaChallengeAndVerifyMutation } from 'data/profile/mfa-challenge-andimport { useMfaEnrollMutation } from 'data/profile/mfa-enroll-mutation'import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'import { useStore } from 'hooks'-import Image from 'next/image'-import { Dispatch, SetStateAction, useEffect, useState } from 'react'-import { Input, Modal } from 'ui'-const AddNewFactorModal = ({ onClose }: { onClose: () => void }) => {+interface AddNewFactorModalProps {+ onClose: () => void+}++const AddNewFactorModal = ({ onClose }: AddNewFactorModalProps) => {const [verificationComplete, setVerificationComplete] = useState(false)// Generate a name with a number between 0 and 1000const [name, setName] = useState(`App ${Math.floor(Math.random() * 1000)}`)const {- mutate: enroll,data,+ mutate: enroll,reset: resetEnrollment,isLoading: isEnrolling,} = useMfaEnrollMutation()@@ -32,10 +37,20 @@ const AddNewFactorModal = ({ onClose }: { onClose: () => void }) => {unenroll({ factorId: data.id })}}+ }, [data])++ useEffect(() => {+ // unenroll({ factorId: '599d65b7-8efe-4295-9baf-6e1bf5360c20' })}, [])return !data ? (- <FirstStep name={name} setName={setName} enroll={enroll} onClose={onClose} />+ <FirstStep+ name={name}+ setName={setName}+ enroll={enroll}+ isEnrolling={isEnrolling}+ onClose={onClose}+ />) : (<SecondStepfactorName={name}@@ -50,17 +65,15 @@ const AddNewFactorModal = ({ onClose }: { onClose: () => void }) => {)}-const FirstStep = ({- name,- setName,- enroll,- onClose,-}: {+interface FirstStepProps {name: stringsetName: Dispatch<SetStateAction<string>>enroll: (params: { factorType: 'totp'; friendlyName?: string }) => void+ isEnrolling: booleanonClose: () => void-}) => {+}++const FirstStep = ({ name, enroll, setName, isEnrolling, onClose }: FirstStepProps) => {return (<ConfirmationModalsize="medium"@@ -69,6 +82,7 @@ const FirstStep = ({buttonLabel="Generate QR"buttonLoadingLabel="Generating QR"buttonDisabled={name.length === 0}+ loading={isEnrolling}onSelectCancel={onClose}onSelectConfirm={() => {enroll({@@ -93,13 +107,7 @@ const FirstStep = ({)}-const SecondStep = ({- factorName,- factor,- isLoading,- onSuccess,- onClose,-}: {+interface SecondStepProps {factorName: stringfactor: {id: string@@ -113,16 +121,17 @@ const SecondStep = ({isLoading: booleanonSuccess: () => voidonClose: () => void-}) => {- const [code, setCode] = useState('')+}+const SecondStep = ({ factorName, factor, isLoading, onSuccess, onClose }: SecondStepProps) => {const { ui } = useStore()+ const [code, setCode] = useState('')- const {- mutate: challengeAndVerify,- isLoading: isVerifying,- isSuccess: verificationComplete,- } = useMfaChallengeAndVerifyMutation({+ const { mutate: unenroll, isLoading: isDeleting } = useMfaUnenrollMutation({+ onSuccess: () => onClose(),+ })++ const { mutate: challengeAndVerify, isLoading: isVerifying } = useMfaChallengeAndVerifyMutation({onError: (error) => {ui.setNotification({category: 'error',@@ -146,7 +155,10 @@ const SecondStep = ({buttonLabel="Confirm"buttonLoadingLabel="Confirming"loading={isVerifying}- onSelectCancel={onClose}+ onSelectCancel={() => {+ // unenroll({ factorId: factor.id })+ onClose()+ }}onSelectConfirm={() => challengeAndVerify({ factorId: factor.id, code })}><Modal.Content>@@ -187,6 +199,7 @@ const SecondStep = ({<Inputlabel="Authentication code"value={code}+ placeholder="XXXXXX"onChange={(e) => setCode(e.target.value)}/></div>diff --git a/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx b/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsxindex 3ef292cc066..7b56226f2fd 100644--- a/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx+++ b/studio/components/interfaces/Account/TOTPFactors/DeleteFactorModal.tsx@@ -1,6 +1,3 @@-import ConfirmationModal from 'components/ui/ConfirmationModal'-import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'-import { useStore } from 'hooks'import {AlertDescription_Shadcn_,AlertTitle_Shadcn_,@@ -9,29 +6,25 @@ import {Modal,} from 'ui'-export const DeleteFactorModal = ({- factorId,- lastFactorToBeDeleted,- onClose,-}: {+import ConfirmationModal from 'components/ui/ConfirmationModal'+import { useMfaUnenrollMutation } from 'data/profile/mfa-unenroll-mutation'+import { useStore } from 'hooks'++interface DeleteFactorModalProps {factorId: stringlastFactorToBeDeleted: booleanonClose: () => void-}) => {- const { ui } = useStore()+}+const DeleteFactorModal = ({+ factorId,+ lastFactorToBeDeleted,+ onClose,+}: DeleteFactorModalProps) => {+ 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.`,- })+ ui.setNotification({ category: 'success', message: `Successfully deleted factor` })onClose()},})@@ -46,9 +39,7 @@ export const DeleteFactorModal = ({buttonLoadingLabel="Deleting"loading={isLoading}onSelectCancel={onClose}- onSelectConfirm={() => {- unenroll({ factorId })- }}+ onSelectConfirm={() => unenroll({ factorId })}><Modal.Content className="py-6"><Alert_Shadcn_ variant="warning">@@ -65,8 +56,8 @@ export const DeleteFactorModal = ({</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">+ <p>Before deleting this factor, consider:</p>+ <ul className="text-light py-1 list-disc mx-4 space-y-1">{lastFactorToBeDeleted ? (<><li>Adding another authenticator app as a factor prior to deleting</li>@@ -84,3 +75,5 @@ export const DeleteFactorModal = ({</ConfirmationModal>)}++export default DeleteFactorModaldiff --git a/studio/components/interfaces/Account/TOTPFactors/index.tsx b/studio/components/interfaces/Account/TOTPFactors/index.tsxindex 4a8f731cf8f..f75c6a53004 100644--- a/studio/components/interfaces/Account/TOTPFactors/index.tsx+++ b/studio/components/interfaces/Account/TOTPFactors/index.tsx@@ -1,8 +1,4 @@-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_,@@ -12,8 +8,13 @@ import {IconAlertCircle,IconTrash,} from 'ui'++import AlertError from 'components/ui/AlertError'+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'+import { useMfaListFactorsQuery } from 'data/profile/mfa-list-factors-query'+import { DATETIME_FORMAT } from 'lib/constants'import AddNewFactorModal from './AddNewFactorModal'-import { DeleteFactorModal } from './DeleteFactorModal'+import DeleteFactorModal from './DeleteFactorModal'const TOTPFactors = () => {const [isAddNewFactorOpen, setIsAddNewFactorOpen] = useState(false)@@ -22,12 +23,12 @@ const TOTPFactors = () => {return (<>- <section>- <span className="text-sm prose color-slate-1000">+ <section className="space-y-3">+ <p className="text-sm text-light">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">+ factor to verify your identity during sign-in.+ </p>+ <div>{isLoading && <GenericSkeletonLoader />}{isError && (<AlertError error={error} subject="Failed to retrieve account security information" />@@ -35,7 +36,7 @@ const TOTPFactors = () => {{isSuccess && (<>{data.totp.length === 1 && (- <Alert_Shadcn_ variant="default">+ <Alert_Shadcn_ variant="default" className="mb-2"><IconAlertCircle className="h-4 w-4" /><AlertTitle_Shadcn_>We recommend configuring two authenticator apps across different devices@@ -45,23 +46,24 @@ const TOTPFactors = () => {</AlertDescription_Shadcn_></Alert_Shadcn_>)}- <div className="py-2">+ <div className="">{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">+ <div className="flex flex-col space-y-0.5">+ <span className="text-sm text">Name: {factor.friendly_name ?? 'No name provided'}</span>- <span className="text-sm text-scale-900">Factor ID: {factor.id}</span>+ <span className="text-sm text-light">Factor ID: {factor.id}</span></div>- <div className="flex items-center gap-2">- <span className="text-sm text-scale-900">+ <div className="flex items-center gap-3">+ <span className="text-sm text-light">Created at {dayjs(factor.updated_at).format(DATETIME_FORMAT)}</span><Buttonsize="tiny"- type="default"+ type="text"+ className="px-1"icon={<IconTrash />}onClick={() => setFactorToBeDeleted(factor.id)}/>@@ -73,14 +75,7 @@ const TOTPFactors = () => {{data.totp.length < 2 ? (<><div className="pt-2">- <Button- size="small"- onClick={() => {- setIsAddNewFactorOpen(true)- }}- >- Add new app- </Button>+ <Button onClick={() => setIsAddNewFactorOpen(true)}>Add new app</Button></div></>) : null}diff --git a/studio/data/profile/mfa-enroll-mutation.ts b/studio/data/profile/mfa-enroll-mutation.tsindex e51a294a5e8..332f3e7aa7a 100644--- a/studio/data/profile/mfa-enroll-mutation.ts+++ b/studio/data/profile/mfa-enroll-mutation.ts@@ -1,6 +1,7 @@import { AuthMFAEnrollResponse, MFAEnrollParams } from '@supabase/supabase-js'import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { auth } from 'lib/gotrue'+import { toast } from 'react-hot-toast'const mfaEnroll = async (params: MFAEnrollParams) => {const { error, data } = await auth.mfa.enroll(params)@@ -13,10 +14,24 @@ type CustomMFAEnrollResponse = NonNullable<AuthMFAEnrollResponse['data']>type CustomMFAEnrollError = NonNullable<AuthMFAEnrollResponse['error']>export const useMfaEnrollMutation = ({+ onSuccess,+ onError,...options}: Omit<UseMutationOptions<CustomMFAEnrollResponse, CustomMFAEnrollError, MFAEnrollParams>,'mutationFn'> = {}) => {- return useMutation((vars) => mfaEnroll(vars), { ...options })+ return useMutation((vars) => mfaEnroll(vars), {+ async onSuccess(data, variables, context) {+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to enroll factor: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ })}diff --git a/studio/data/profile/mfa-list-factors-query.ts b/studio/data/profile/mfa-list-factors-query.tsindex 47b44458bae..108cce7bbdb 100644--- a/studio/data/profile/mfa-list-factors-query.ts+++ b/studio/data/profile/mfa-list-factors-query.ts@@ -1,4 +1,4 @@-import { AuthMFAListFactorsResponse } from '@supabase/supabase-js'+import { AuthMFAListFactorsResponse, Factor } from '@supabase/supabase-js'import { useQuery, UseQueryOptions } from '@tanstack/react-query'import { auth } from 'lib/gotrue'import { profileKeys } from './keys'@@ -10,6 +10,7 @@ export async function getMfaListFactors() {return data}+export type MFAFactor = Factortype CustomMFAListFactorsData = NonNullable<AuthMFAListFactorsResponse['data']>type CustomMFAListFactorsError = NonNullable<AuthMFAListFactorsResponse['error']>diff --git a/studio/data/profile/mfa-unenroll-mutation.ts b/studio/data/profile/mfa-unenroll-mutation.tsindex c3ab09cfa94..e10a772e0f3 100644--- a/studio/data/profile/mfa-unenroll-mutation.ts+++ b/studio/data/profile/mfa-unenroll-mutation.ts@@ -2,6 +2,7 @@ import { AuthMFAUnenrollResponse, MFAUnenrollParams } from '@supabase/supabase-jimport { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { auth } from 'lib/gotrue'import { profileKeys } from './keys'+import { toast } from 'react-hot-toast'const mfaUnenroll = async (params: MFAUnenrollParams) => {const { error, data } = await auth.mfa.unenroll(params)@@ -15,6 +16,7 @@ type CustomMFAUnenrollError = NonNullable<AuthMFAUnenrollResponse['error']>export const useMfaUnenrollMutation = ({onSuccess,+ onError,...options}: Omit<UseMutationOptions<CustomMFAUnenrollResponse, CustomMFAUnenrollError, MFAUnenrollParams>,@@ -32,6 +34,13 @@ export const useMfaUnenrollMutation = ({await onSuccess?.(data, variables, context)},+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to delete factor: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },...options,})}diff --git a/studio/pages/account/security.tsx b/studio/pages/account/security.tsxindex baf312d114c..b34c08743a4 100644--- a/studio/pages/account/security.tsx+++ b/studio/pages/account/security.tsx@@ -37,16 +37,18 @@ const Security: NextPageWithLayout = () => {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 className="flex flex-row gap-4 items-center py-1">+ <IconSmartphone strokeWidth={1.5} />+ <span className="text-sm">Authenticator app</span></div>{data ? (<Badge- color={data.totp.length === 0 ? 'red' : data.totp.length === 1 ? 'yellow' : 'green'}+ color={+ data.totp.length === 0 ? 'gray' : data.totp.length === 1 ? 'yellow' : 'green'+ }>- {data.totp.length} apps configured+ {data.totp.length} app{data.totp.length === 1 ? '' : 's'} configured</Badge>) : null}</button>