Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): clarify MFA backup authenticator copy (#49083)

Danny White89cd156e3929
diff --git a/apps/studio/components/interfaces/Account/TOTPFactors/index.tsx b/apps/studio/components/interfaces/Account/TOTPFactors/index.tsx
index 61c79ac6bec..d8952f9625b 100644
--- a/apps/studio/components/interfaces/Account/TOTPFactors/index.tsx
+++ b/apps/studio/components/interfaces/Account/TOTPFactors/index.tsx
@@ -1,6 +1,17 @@
import dayjs from 'dayjs'
+import { Plus } from 'lucide-react'
import { useState } from 'react'
-import { Button } from 'ui'
+import { Button, Card, CardContent } from 'ui'
+import { Admonition } from 'ui-patterns/Admonition'
+import {
+ PageSection,
+ PageSectionAside,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { AddNewFactorModal } from './AddNewFactorModal'
@@ -14,54 +25,86 @@ export const TOTPFactors = () => {
const [factorToBeDeleted, setFactorToBeDeleted] = useState<string | null>(null)
const { data, isPending: isLoading, isError, isSuccess, error } = useMfaListFactorsQuery()
+ const totpFactors = data?.totp ?? []
+ const canAddApp = isSuccess && totpFactors.length < 2
+ const shouldShowLockoutWarning = isSuccess && totpFactors.length === 1
+
+ const handleAddNewApp = () => setIsAddNewFactorOpen(true)
+
return (
<>
- <section className="space-y-3">
- <p className="text-sm text-foreground-light">
- Use an authenticator app (like Google Authenticator or 1Password) to protect your account.
- </p>
- <div>
- {isLoading && <GenericSkeletonLoader />}
+ <PageSection>
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Multi-factor authentication</PageSectionTitle>
+ <PageSectionDescription>
+ Use an authenticator app (like Google Authenticator or 1Password) to protect your
+ account.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ {canAddApp && (
+ <PageSectionAside>
+ <Button variant="primary" icon={<Plus />} onClick={handleAddNewApp}>
+ Add app
+ </Button>
+ </PageSectionAside>
+ )}
+ </PageSectionMeta>
+ <PageSectionContent className="flex flex-col gap-4">
+ {shouldShowLockoutWarning && (
+ <Admonition
+ type="danger"
+ layout="responsive"
+ title="Avoid being locked out"
+ description="Add a backup authenticator app now. Losing access to your only app will permanently lock you out of your account."
+ actions={
+ <Button variant="default" icon={<Plus />} onClick={handleAddNewApp}>
+ Add another app
+ </Button>
+ }
+ />
+ )}
+ {isLoading && (
+ <Card>
+ <CardContent>
+ <GenericSkeletonLoader />
+ </CardContent>
+ </Card>
+ )}
{isError && (
<AlertError error={error} subject="Failed to retrieve account security information" />
)}
{isSuccess && (
- <>
- <div>
- {data.totp.map((factor) => {
- return (
- <div key={factor.id} className="flex flex-row justify-between py-2">
- <p className="text-sm text-foreground flex items-center space-x-2">
- <span className="text-foreground-light">Name:</span>{' '}
- <span>{factor.friendly_name ?? 'No name provided'}</span>
- </p>
- <div className="flex items-center gap-4">
- <p className="text-sm text-foreground-light">
+ <Card>
+ {totpFactors.length === 0 ? (
+ <CardContent>
+ <p className="text-sm text-foreground-lighter">No authenticator apps yet.</p>
+ </CardContent>
+ ) : (
+ <div className="divide-y">
+ {totpFactors.map((factor) => (
+ <CardContent key={factor.id} className="flex justify-between items-center py-4">
+ <div>
+ <p className="text-sm">{factor.friendly_name ?? 'No name provided'}</p>
+ <p className="text-sm text-foreground-lighter">
Added on {dayjs(factor.created_at).format(DATETIME_FORMAT)}
</p>
- <Button
- size="tiny"
- variant="default"
- onClick={() => setFactorToBeDeleted(factor.id)}
- >
- Remove
- </Button>
</div>
- </div>
- )
- })}
- </div>
- {data.totp.length < 2 ? (
- <>
- <div className="pt-2">
- <Button onClick={() => setIsAddNewFactorOpen(true)}>Add new app</Button>
- </div>
- </>
- ) : null}
- </>
+ <Button
+ size="tiny"
+ variant="default"
+ onClick={() => setFactorToBeDeleted(factor.id)}
+ >
+ Delete{' '}
+ </Button>
+ </CardContent>
+ ))}
+ </div>
+ )}
+ </Card>
)}
- </div>
- </section>
+ </PageSectionContent>
+ </PageSection>
<AddNewFactorModal
visible={isAddNewFactorOpen}
onClose={() => setIsAddNewFactorOpen(false)}
@@ -69,7 +112,7 @@ export const TOTPFactors = () => {
<DeleteFactorModal
visible={factorToBeDeleted !== null}
factorId={factorToBeDeleted}
- lastFactorToBeDeleted={data?.totp.length === 1}
+ lastFactorToBeDeleted={totpFactors.length === 1}
onClose={() => setFactorToBeDeleted(null)}
/>
</>
diff --git a/apps/studio/pages/account/security.tsx b/apps/studio/pages/account/security.tsx
index db7ec4be0b7..95ceb219239 100644
--- a/apps/studio/pages/account/security.tsx
+++ b/apps/studio/pages/account/security.tsx
@@ -1,6 +1,3 @@
-import { Lock } from 'lucide-react'
-import { Badge, Card, CardContent, CardHeader } from 'ui'
-import { Admonition } from 'ui-patterns/Admonition'
import { PageContainer } from 'ui-patterns/PageContainer'
import {
PageHeader,
@@ -15,15 +12,12 @@ import AccountLayout from '@/components/layouts/AccountLayout/AccountLayout'
import { AppLayout } from '@/components/layouts/AppLayout/AppLayout'
import { DefaultLayout } from '@/components/layouts/DefaultLayout'
import { UnknownInterface } from '@/components/ui/UnknownInterface'
-import { useMfaListFactorsQuery } from '@/data/profile/mfa-list-factors-query'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import type { NextPageWithLayout } from '@/types'
const Security: NextPageWithLayout = () => {
const showSecuritySettings = useIsFeatureEnabled('account:show_security_settings')
- const { data } = useMfaListFactorsQuery({ enabled: showSecuritySettings })
-
if (!showSecuritySettings) {
return <UnknownInterface urlBack={`/account/me`} />
}
@@ -41,32 +35,7 @@ const Security: NextPageWithLayout = () => {
</PageHeaderMeta>
</PageHeader>
<PageContainer size="small">
- {data?.totp.length === 1 && (
- <Admonition
- className="mt-8"
- type="danger"
- layout="horizontal"
- title="Avoid being locked out"
- description="Add a backup sign-in method now. Otherwise, losing access to your authenticator app will permanently lock you out of your account."
- />
- )}
- <Card className="mt-8">
- <CardHeader className="py-3 flex flex-row items-center justify-between">
- <div className="flex flex-row gap-4 items-center py-1 mb-0">
- <Lock size={18} strokeWidth={1.5} />
- <span className="text-sm">Multi-factor authentication (MFA)</span>
- </div>
-
- {data ? (
- <Badge variant={data.totp.length === 0 ? 'default' : 'success'}>
- {data.totp.length} app{data.totp.length === 1 ? '' : 's'} configured
- </Badge>
- ) : null}
- </CardHeader>
- <CardContent>
- <TOTPFactors />
- </CardContent>
- </Card>
+ <TOTPFactors />
</PageContainer>
</>
)