From 1b781922537a108b788129eb30849ccdd2be4375 Mon Sep 17 00:00:00 2001 From: "Rudy B." Date: Fri, 24 Apr 2026 19:30:17 +0200 Subject: [PATCH] feat(2FA): add user security settings page --- src/app/(main)/settings/SettingsNav.tsx | 8 +- .../settings/security/UserSecurityPage.tsx | 94 +++++++++++++++++++ src/app/(main)/settings/security/page.tsx | 10 ++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/app/(main)/settings/security/UserSecurityPage.tsx create mode 100644 src/app/(main)/settings/security/page.tsx diff --git a/src/app/(main)/settings/SettingsNav.tsx b/src/app/(main)/settings/SettingsNav.tsx index 8c97b9d6c..8102ad7a6 100644 --- a/src/app/(main)/settings/SettingsNav.tsx +++ b/src/app/(main)/settings/SettingsNav.tsx @@ -2,7 +2,7 @@ import { Column, Focusable, Row, Text, Tooltip, TooltipTrigger } from '@umami/re import Link from '@/components/common/Link'; import { IconLabel } from '@/components/common/IconLabel'; import { useMessages, useNavigation } from '@/components/hooks'; -import { ArrowLeft, Settings2, UserCircle, Users } from '@/components/icons'; +import { ArrowLeft, Settings2, ShieldCheck, UserCircle, Users } from '@/components/icons'; export function SettingsNav({ isCollapsed, @@ -41,6 +41,12 @@ export function SettingsNav({ path: renderUrl('/settings/teams'), icon: , }, + { + id: 'security', + label: t(labels.security), + path: renderUrl('/settings/security'), + icon: , + }, ], }, ]; diff --git a/src/app/(main)/settings/security/UserSecurityPage.tsx b/src/app/(main)/settings/security/UserSecurityPage.tsx new file mode 100644 index 000000000..2e23786e5 --- /dev/null +++ b/src/app/(main)/settings/security/UserSecurityPage.tsx @@ -0,0 +1,94 @@ +'use client'; +import { Column, Row, Switch, Text, Tooltip, TooltipTrigger } from '@umami/react-zen'; +import { useState } from 'react'; +import { Badge } from '@/components/common/Badge'; +import { PageBody } from '@/components/common/PageBody'; +import { PageHeader } from '@/components/common/PageHeader'; +import { Panel } from '@/components/common/Panel'; +import { useMessages, useTwoFactorStatusQuery } from '@/components/hooks'; +import { TwoFactorDisableModal } from '@/components/modals/TwoFactorDisableModal'; +import { TwoFactorSetupModal } from '@/components/modals/TwoFactorSetupModal'; +import { useQueryClient } from '@tanstack/react-query'; + +export function UserSecurityPage() { + const { t, labels, messages } = useMessages(); + const { data: status, isLoading } = useTwoFactorStatusQuery(true); + const queryClient = useQueryClient(); + const [showSetup, setShowSetup] = useState(false); + const [showDisable, setShowDisable] = useState(false); + + const isEnabled = status?.isEnabled ?? false; + const isRequired = status?.isRequired ?? false; + + const handleToggle = (value: boolean) => { + if (value) { + setShowSetup(true); + } else { + setShowDisable(true); + } + }; + + const handleSetupClose = () => { + setShowSetup(false); + queryClient.invalidateQueries({ queryKey: ['2fa-status'] }); + }; + + const handleDisableSuccess = () => { + setShowDisable(false); + queryClient.invalidateQueries({ queryKey: ['2fa-status'] }); + }; + + if (isLoading) return null; + + return ( + + + + + + + {t(labels.twoFactorAuth)} + {isEnabled ? ( + {t(labels.twoFactorActive)} + ) : ( + {t(labels.twoFactorStatusNotConfigured)} + )} + + + {isEnabled ? ( + {t(messages.twoFactorActiveDescription)} + ) : ( + {t(messages.twoFactorUserDescription)} + )} + + + + + {t(labels.twoFactorEnable)} + + {t(messages.twoFactorRequiredMessage)} + + + {isEnabled && isRequired && ( + + {t(messages.twoFactorRequiredMessage)} + + )} + + + + + {showSetup && } + {showDisable && ( + setShowDisable(false)} + onSuccess={handleDisableSuccess} + /> + )} + + ); +} diff --git a/src/app/(main)/settings/security/page.tsx b/src/app/(main)/settings/security/page.tsx new file mode 100644 index 000000000..e955d0eb5 --- /dev/null +++ b/src/app/(main)/settings/security/page.tsx @@ -0,0 +1,10 @@ +import type { Metadata } from 'next'; +import { UserSecurityPage } from './UserSecurityPage'; + +export default function () { + return ; +} + +export const metadata: Metadata = { + title: 'Security', +};