mfa.tsx73 lines · main
| 1 | import { PermissionAction } from '@supabase/shared-types/out/constants' |
| 2 | import { useParams } from 'common' |
| 3 | import { PageContainer } from 'ui-patterns/PageContainer' |
| 4 | import { |
| 5 | PageHeader, |
| 6 | PageHeaderDescription, |
| 7 | PageHeaderMeta, |
| 8 | PageHeaderSummary, |
| 9 | PageHeaderTitle, |
| 10 | } from 'ui-patterns/PageHeader' |
| 11 | import { PageSection, PageSectionContent } from 'ui-patterns/PageSection' |
| 12 | import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' |
| 13 | |
| 14 | import { MfaAuthSettingsForm } from '@/components/interfaces/Auth/MfaAuthSettingsForm/MfaAuthSettingsForm' |
| 15 | import AuthLayout from '@/components/layouts/AuthLayout/AuthLayout' |
| 16 | import DefaultLayout from '@/components/layouts/DefaultLayout' |
| 17 | import NoPermission from '@/components/ui/NoPermission' |
| 18 | import { UnknownInterface } from '@/components/ui/UnknownInterface' |
| 19 | import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' |
| 20 | import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' |
| 21 | import type { NextPageWithLayout } from '@/types' |
| 22 | |
| 23 | const MfaPage: NextPageWithLayout = () => { |
| 24 | const { ref } = useParams() |
| 25 | const showMFA = useIsFeatureEnabled('authentication:multi_factor') |
| 26 | |
| 27 | const { can: canReadAuthSettings, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissions( |
| 28 | PermissionAction.READ, |
| 29 | 'custom_config_gotrue' |
| 30 | ) |
| 31 | |
| 32 | if (!showMFA) { |
| 33 | return <UnknownInterface urlBack={`/project/${ref}/auth/users`} /> |
| 34 | } |
| 35 | |
| 36 | if (isPermissionsLoaded && !canReadAuthSettings) { |
| 37 | return <NoPermission isFullPage resourceText="access your project's authentication settings" /> |
| 38 | } |
| 39 | |
| 40 | return ( |
| 41 | <> |
| 42 | <PageHeader size="default"> |
| 43 | <PageHeaderMeta> |
| 44 | <PageHeaderSummary> |
| 45 | <PageHeaderTitle>Multi-Factor Authentication (MFA)</PageHeaderTitle> |
| 46 | <PageHeaderDescription> |
| 47 | Requires users to provide additional verification factors to authenticate |
| 48 | </PageHeaderDescription> |
| 49 | </PageHeaderSummary> |
| 50 | </PageHeaderMeta> |
| 51 | </PageHeader> |
| 52 | <PageContainer size="default"> |
| 53 | {!isPermissionsLoaded ? ( |
| 54 | <PageSection> |
| 55 | <PageSectionContent> |
| 56 | <GenericSkeletonLoader /> |
| 57 | </PageSectionContent> |
| 58 | </PageSection> |
| 59 | ) : ( |
| 60 | <MfaAuthSettingsForm /> |
| 61 | )} |
| 62 | </PageContainer> |
| 63 | </> |
| 64 | ) |
| 65 | } |
| 66 | |
| 67 | MfaPage.getLayout = (page) => ( |
| 68 | <DefaultLayout> |
| 69 | <AuthLayout title="Multi-Factor">{page}</AuthLayout> |
| 70 | </DefaultLayout> |
| 71 | ) |
| 72 | |
| 73 | export default MfaPage |