Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add settings pages (#2413)

Leendert de Borst79095c05190a
diff --git a/apps/web/src/pages/settings/Apps.tsx b/apps/web/src/pages/settings/Apps.tsx
new file mode 100644
index 000000000..00970b710
--- /dev/null
+++ b/apps/web/src/pages/settings/Apps.tsx
@@ -0,0 +1,91 @@
+import React from 'react';
+import { useTranslation } from 'react-i18next';
+
+import PageContent from '@/components/shared/PageContent';
+import PageHeader from '@/components/shared/PageHeader';
+import { usePageTitle } from '@/hooks/usePageTitle';
+
+/**
+ * A downloadable client (the shared BrowserExtensionInfo / MobileAppInfo).
+ */
+type AppInfo = {
+ name: string;
+ iconPath: string;
+ downloadUrl: string;
+ isAvailable: boolean;
+};
+
+/** The browser extensions, in the order of the shared constants. */
+const BROWSER_EXTENSIONS: AppInfo[] = [
+ { name: 'Google Chrome', iconPath: '/img/browser-icons/chrome.svg', downloadUrl: 'https://chromewebstore.google.com/detail/aliasvault/bmoggiinmnodjphdjnmpcnlleamkfedj', isAvailable: true },
+ { name: 'Firefox', iconPath: '/img/browser-icons/firefox.svg', downloadUrl: 'https://addons.mozilla.org/en-US/firefox/addon/aliasvault/', isAvailable: true },
+ { name: 'Safari', iconPath: '/img/browser-icons/safari.svg', downloadUrl: 'https://apps.apple.com/app/6743163173', isAvailable: true },
+ { name: 'Microsoft Edge', iconPath: '/img/browser-icons/edge.svg', downloadUrl: 'https://microsoftedge.microsoft.com/addons/detail/aliasvault/kabaanafahnjkfkplbnllebdmppdemfo', isAvailable: true },
+ { name: 'Brave', iconPath: '/img/browser-icons/brave.svg', downloadUrl: 'https://chromewebstore.google.com/detail/aliasvault/bmoggiinmnodjphdjnmpcnlleamkfedj', isAvailable: true },
+];
+
+/** The mobile apps. */
+const MOBILE_APPS: AppInfo[] = [
+ { name: 'iOS', iconPath: '/img/mobile-icons/ios.svg', downloadUrl: 'https://apps.apple.com/app/id6745490915', isAvailable: true },
+ { name: 'Android', iconPath: '/img/mobile-icons/android.svg', downloadUrl: 'https://play.google.com/store/apps/details?id=net.aliasvault.app', isAvailable: true },
+];
+
+/**
+ * A row for one app with its install or download link.
+ */
+const AppRow: React.FC<{ app: AppInfo; buttonText: string; comingSoonText: string }> = ({ app, buttonText, comingSoonText }) => (
+ <div className="p-4 border rounded-lg dark:border-gray-700 flex justify-between items-center">
+ <div className="flex items-center">
+ <img src={app.iconPath} alt={app.name} className="w-8 h-8 mr-3" />
+ <h4 className="text-lg font-medium text-gray-900 dark:text-white">{app.name}</h4>
+ </div>
+ {app.isAvailable ? (
+ <a href={app.downloadUrl} target="_blank" rel="noreferrer" className="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900">
+ {buttonText}
+ </a>
+ ) : (
+ <span className="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-gray-100 rounded-lg dark:text-gray-400 dark:bg-gray-800">{comingSoonText}</span>
+ )}
+ </div>
+);
+
+/**
+ * The extensions and apps page.
+ */
+const AppsSettings: React.FC = () => {
+ const { t } = useTranslation();
+ const tk = 'pages.main.settings.apps';
+ usePageTitle(t(`${tk}.PageTitle`));
+
+ return (
+ <>
+ <PageHeader breadcrumbItems={[{ displayName: t(`${tk}.BreadcrumbTitle`) }]} title={t(`${tk}.PageTitle`)} description={t(`${tk}.PageDescription`)} />
+
+ <PageContent>
+ <div className="p-4 mb-4 mx-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
+ <div className="mb-6">
+ <h3 className="text-lg font-medium text-gray-900 dark:text-white mb-2">{t(`${tk}.BrowserExtensionsTitle`)}</h3>
+ <p className="text-gray-600 dark:text-gray-400">{t(`${tk}.BrowserExtensionsDescription`)}</p>
+ </div>
+
+ <div className="mb-8">
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
+ {BROWSER_EXTENSIONS.map(app => <AppRow key={app.name} app={app} buttonText={t(`${tk}.InstallButton`)} comingSoonText={t(`${tk}.ComingSoonText`)} />)}
+ </div>
+ </div>
+
+ <div className="mb-6">
+ <h3 className="text-lg font-medium text-gray-900 dark:text-white mb-2">{t(`${tk}.MobileAppsTitle`)}</h3>
+ <p className="text-gray-600 dark:text-gray-400 mb-4">{t(`${tk}.MobileAppsDescription`)}</p>
+ </div>
+
+ <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
+ {MOBILE_APPS.map(app => <AppRow key={app.name} app={app} buttonText={t(`${tk}.DownloadButton`)} comingSoonText={t(`${tk}.ComingSoonText`)} />)}
+ </div>
+ </div>
+ </PageContent>
+ </>
+ );
+};
+
+export default AppsSettings;
diff --git a/apps/web/src/pages/settings/General.tsx b/apps/web/src/pages/settings/General.tsx
new file mode 100644
index 000000000..502ac81f9
--- /dev/null
+++ b/apps/web/src/pages/settings/General.tsx
@@ -0,0 +1,232 @@
+import { getIdentityAgeRanges, getIdentityLanguages } from '@aliasvault/client/rust/RustCore';
+import { getLanguageInfo, resolveDefaultLanguage } from '@aliasvault/models/defaults';
+import React, { useCallback, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import DefaultPasswordSettings from '@/components/settings/DefaultPasswordSettings';
+import PageContent from '@/components/shared/PageContent';
+import PageHeader from '@/components/shared/PageHeader';
+import { getAppConfig } from '@/config/AppConfig';
+import { useDb } from '@/context/DbContext';
+import { usePageTitle } from '@/hooks/usePageTitle';
+import { useVaultMutate } from '@/hooks/useVaultMutate';
+import { AVAILABLE_LANGUAGES } from '@/i18n/config';
+import { changeLanguage } from '@/i18n/i18n';
+import { vaultStore } from '@/vault/VaultStore';
+
+const SELECT_CLASSES = 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500';
+const LABEL_CLASSES = 'block mb-2 text-sm font-medium text-gray-900 dark:text-white';
+const CARD_CLASSES = 'p-4 mb-4 mx-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800';
+
+/**
+ * Whether the private domain list holds a usable domain.
+ */
+const hasValidPrivateDomains = (domains: string[]): boolean => domains.length > 0 && !(domains.length === 1 && (domains[0].trim().length === 0 || domains[0] === 'DISABLED.TLD'));
+
+/**
+ * The general settings page.
+ */
+const GeneralSettings: React.FC = () => {
+ const { t, i18n } = useTranslation();
+ const dbContext = useDb();
+ const { executeVaultMutationAsync } = useVaultMutate();
+ const tk = 'pages.main.settings.general';
+ usePageTitle(t(`${tk}.PageTitle`));
+
+ const [privateDomains, setPrivateDomains] = useState<string[]>([]);
+ const [publicDomains, setPublicDomains] = useState<string[]>([]);
+ const [defaultEmailDomain, setDefaultEmailDomain] = useState('');
+ const [autoEmailRefresh, setAutoEmailRefresh] = useState(true);
+ const [identityLanguages, setIdentityLanguages] = useState<string[]>([]);
+ const [ageRanges, setAgeRanges] = useState<string[]>([]);
+ const [identityLanguage, setIdentityLanguage] = useState('');
+ const [identityGender, setIdentityGender] = useState('random');
+ const [identityAgeRange, setIdentityAgeRange] = useState('random');
+ const [appLanguage, setAppLanguage] = useState(i18n.language);
+ const [clipboardClearSeconds, setClipboardClearSeconds] = useState('10');
+
+ /**
+ * Write a vault setting and push it.
+ */
+ const updateSetting = useCallback(async (key: string, value: string): Promise<void> => {
+ await executeVaultMutationAsync(async () => {
+ dbContext.sqliteClient?.settings.updateSetting(key, value);
+ });
+ }, [dbContext.sqliteClient, executeVaultMutationAsync]);
+
+ /**
+ * The identity language: the explicit setting, or the one matching the UI language.
+ */
+ const resolveIdentityLanguage = useCallback((languages: string[]): string => {
+ const explicit = dbContext.sqliteClient?.settings.getDefaultIdentityLanguage() ?? '';
+ return explicit.trim().length > 0 ? explicit : resolveDefaultLanguage(i18n.language, languages);
+ }, [dbContext.sqliteClient, i18n.language]);
+
+ useEffect(() => {
+ const client = dbContext.sqliteClient;
+ if (!client) {
+ return;
+ }
+ let cancelled = false;
+
+ /**
+ * Load the domains and the current settings.
+ */
+ const load = async (): Promise<void> => {
+ const metadata = await vaultStore.getVaultMetadata();
+ const hidden = metadata?.hiddenPrivateEmailDomains ?? getAppConfig().hiddenPrivateEmailDomains;
+ const privateList = (metadata?.privateEmailDomains ?? getAppConfig().privateEmailDomains).filter(d => !hidden.includes(d));
+ const publicList = metadata?.publicEmailDomains ?? [];
+ const languages = (await getIdentityLanguages()).sort((a, b) => getLanguageInfo(a).label.localeCompare(getLanguageInfo(b).label));
+ const ranges = await getIdentityAgeRanges();
+ if (cancelled) {
+ return;
+ }
+
+ setPrivateDomains(privateList);
+ setPublicDomains(publicList);
+ let domain = client.settings.getDefaultEmailDomain();
+ if (domain.length === 0 || hidden.includes(domain)) {
+ domain = hasValidPrivateDomains(privateList) ? privateList[0] : publicList[0] ?? '';
+ }
+ setDefaultEmailDomain(domain);
+ setAutoEmailRefresh(client.settings.getSetting('AutoEmailRefresh', 'True').toLowerCase() === 'true');
+ setIdentityLanguages(languages);
+ setAgeRanges(ranges);
+ setIdentityLanguage(resolveIdentityLanguage(languages));
+ setIdentityGender(client.settings.getDefaultIdentityGender());
+ setIdentityAgeRange(client.settings.getDefaultIdentityAgeRange());
+ setClipboardClearSeconds(client.settings.getSetting('ClipboardClearSeconds', '10'));
+ };
+ void load();
+ return (): void => {
+ cancelled = true;
+ };
+ }, [dbContext.sqliteClient, resolveIdentityLanguage]);
+
+ /**
+ * Switch the UI language, remembered in the vault and locally, and refresh the derived identity language.
+ */
+ const updateAppLanguage = async (code: string): Promise<void> => {
+ setAppLanguage(code);
+ await changeLanguage(code);
+ await updateSetting('AppLanguage', code);
+ setIdentityLanguage(resolveIdentityLanguage(identityLanguages));
+ };
+
+ return (
+ <>
+ <PageHeader breadcrumbItems={[{ displayName: t(`${tk}.BreadcrumbTitle`) }]} title={t(`${tk}.PageTitle`)} description={t(`${tk}.PageDescription`)} />
+
+ <PageContent>
+ <div className={CARD_CLASSES}>
+ <h3 className="mb-4 text-lg font-medium text-gray-900 dark:text-white">{t(`${tk}.AppLanguageTitle`)}</h3>
+ <div className="mb-4">
+ <label htmlFor="appLanguage" className={LABEL_CLASSES}>{t(`${tk}.AppLanguageLabel`)}</label>
+ <select id="appLanguage" value={appLanguage} onChange={e => void updateAppLanguage(e.target.value)} className={SELECT_CLASSES}>
+ {AVAILABLE_LANGUAGES.map(language => <option key={language.code} value={language.code}>{language.flag} {language.nativeName}</option>)}
+ </select>
+ <span className="block text-sm font-normal text-gray-500 truncate dark:text-gray-400">{t(`${tk}.AppLanguageDescription`)}</span>
+ </div>
+ </div>
+
+ <div className={CARD_CLASSES}>
+ <h3 className="mb-4 text-lg font-medium text-gray-900 dark:text-white">{t(`${tk}.EmailSettingsTitle`)}</h3>
+ <div className="mb-4">
+ <label htmlFor="defaultEmailDomain" className={LABEL_CLASSES}>{t(`${tk}.DefaultEmailDomainLabel`)}</label>
+ <select id="defaultEmailDomain" value={defaultEmailDomain} onChange={(e) => {
+ setDefaultEmailDomain(e.target.value);
+ void updateSetting('DefaultEmailDomain', e.target.value);
+ }} className={SELECT_CLASSES}>
+ <optgroup label={t(`${tk}.PrivateDomainsLabel`)}>
+ {hasValidPrivateDomains(privateDomains)
+ ? privateDomains.map(domain => <option key={domain} value={domain}>{domain}</option>)
+ : <option disabled value="_">{t(`${tk}.PrivateDomainsDisabledLabel`)}</option>}
+ </optgroup>
+ <optgroup label={t(`${tk}.PublicDomainsLabel`)}>
+ {publicDomains.map(domain => <option key={domain} value={domain}>{domain}</option>)}
+ </optgroup>
+ </select>
+ <span className="block text-sm font-normal text-gray-500 dark:text-gray-400 mt-2">
+ {t(`${tk}.DefaultEmailDomainDescription`)} {t(`${tk}.DefaultEmailDomainDescriptionNote`)} <a href="https://docs.aliasvault.com/misc/private-vs-public-email.html" className="text-primary-500 hover:text-primary-700 hover:underline" target="_blank" rel="noopener noreferrer">{t(`${tk}.DefaultEmailDomainLearnMore`)}</a>.
+ </span>
+ </div>
+
+ <div className="flex items-center mb-4">
+ <input id="autoEmailRefresh" type="checkbox" checked={autoEmailRefresh} onChange={(e) => {
+ setAutoEmailRefresh(e.target.checked);
+ void updateSetting('AutoEmailRefresh', e.target.checked ? 'True' : 'False');
+ }} className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600" />
+ <label htmlFor="autoEmailRefresh" className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">{t(`${tk}.AutoEmailRefreshLabel`)}</label>
+ </div>
+ </div>
+
+ <div className={CARD_CLASSES}>
+ <h3 className="mb-4 text-lg font-medium text-gray-900 dark:text-white">{t(`${tk}.AliasSettingsTitle`)}</h3>
+
+ <div className="mb-4">
+ <label htmlFor="defaultIdentityLanguage" className={LABEL_CLASSES}>{t(`${tk}.AliasGenerationLanguageLabel`)}</label>
+ <select id="defaultIdentityLanguage" value={identityLanguage} onChange={(e) => {
+ setIdentityLanguage(e.target.value);
+ void updateSetting('DefaultIdentityLanguage', e.target.value);
+ }} className={SELECT_CLASSES}>
+ {identityLanguages.map(code => <option key={code} value={code}>{getLanguageInfo(code).flag} {getLanguageInfo(code).label}</option>)}
+ </select>
+ <span className="block text-sm font-normal text-gray-500 truncate dark:text-gray-400">{t(`${tk}.AliasGenerationLanguageDescription`)}</span>
+ </div>
+
+ <div className="mb-4">
+ <label htmlFor="defaultIdentityGender" className={LABEL_CLASSES}>{t(`${tk}.AliasGenerationGenderLabel`)}</label>
+ <select id="defaultIdentityGender" value={identityGender} onChange={(e) => {
+ setIdentityGender(e.target.value);
+ void updateSetting('DefaultIdentityGender', e.target.value);
+ }} className={SELECT_CLASSES}>
+ <option value="random">{t(`${tk}.RandomOption`)}</option>
+ <option value="male">{t(`${tk}.MaleOption`)}</option>
+ <option value="female">{t(`${tk}.FemaleOption`)}</option>
+ </select>
+ <span className="block text-sm font-normal text-gray-500 truncate dark:text-gray-400">{t(`${tk}.AliasGenerationGenderDescription`)}</span>
+ </div>
+
+ <div className="mb-4">
+ <label htmlFor="defaultIdentityAgeRange" className={LABEL_CLASSES}>{t(`${tk}.AliasGenerationAgeRangeLabel`)}</label>
+ <select id="defaultIdentityAgeRange" value={identityAgeRange} onChange={(e) => {
+ setIdentityAgeRange(e.target.value);
+ void updateSetting('DefaultIdentityAgeRange', e.target.value);
+ }} className={SELECT_CLASSES}>
+ {ageRanges.map(range => <option key={range} value={range}>{range === 'random' ? t(`${tk}.RandomOption`) : range}</option>)}
+ </select>
+ <span className="block text-sm font-normal text-gray-500 truncate dark:text-gray-400">{t(`${tk}.AliasGenerationAgeRangeDescription`)}</span>
+ </div>
+ </div>
+
+ <div className={CARD_CLASSES}>
+ <h3 className="mb-4 text-lg font-medium text-gray-900 dark:text-white">{t(`${tk}.ClipboardSettingsTitle`)}</h3>
+ <div className="mb-4">
+ <label htmlFor="clipboardClearSeconds" className={LABEL_CLASSES}>{t(`${tk}.ClipboardClearSecondsLabel`)}</label>
+ <select id="clipboardClearSeconds" value={clipboardClearSeconds} onChange={(e) => {
+ setClipboardClearSeconds(e.target.value);
+ void updateSetting('ClipboardClearSeconds', e.target.value);
+ }} className={SELECT_CLASSES}>
+ <option value="0">{t(`${tk}.ClipboardClearDisabledOption`)}</option>
+ <option value="5">{t(`${tk}.ClipboardClear5SecondsOption`)}</option>
+ <option value="10">{t(`${tk}.ClipboardClear10SecondsOption`)}</option>
+ <option value="15">{t(`${tk}.ClipboardClear15SecondsOption`)}</option>
+ </select>
+ <span className="block text-sm font-normal text-gray-500 dark:text-gray-400">{t(`${tk}.ClipboardClearSecondsDescription`)}</span>
+ <div className="mt-2 p-3 bg-yellow-50 border border-yellow-200 rounded-lg dark:bg-yellow-900/20 dark:border-yellow-800">
+ <p className="text-sm text-yellow-800 dark:text-yellow-200">{t(`${tk}.ClipboardClearLimitationNote`)}</p>
+ </div>
+ </div>
+ </div>
+
+ <div className={CARD_CLASSES}>
+ <h3 className="mb-4 text-lg font-medium text-gray-900 dark:text-white">{t(`${tk}.PasswordSettingsTitle`)}</h3>
+ <DefaultPasswordSettings />
+ </div>
+ </PageContent>
+ </>
+ );
+};
+
+export default GeneralSettings;
diff --git a/apps/web/src/pages/settings/security/Security.tsx b/apps/web/src/pages/settings/security/Security.tsx
new file mode 100644
index 000000000..c9f9d2310
--- /dev/null
+++ b/apps/web/src/pages/settings/security/Security.tsx
@@ -0,0 +1,53 @@
+import React, { useCallback, useEffect, useRef } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import ActiveSessionsSection from '@/components/settings/security/ActiveSessionsSection';
+import DeleteAccountSection from '@/components/settings/security/DeleteAccountSection';
+import PasswordChangeSection from '@/components/settings/security/PasswordChangeSection';
+import QuickVaultUnlockSection from '@/components/settings/security/QuickVaultUnlockSection';
+import RecentAuthLogsSection from '@/components/settings/security/RecentAuthLogsSection';
+import type { SectionHandle } from '@/components/settings/security/SecuritySection';
+import TwoFactorAuthenticationSection from '@/components/settings/security/TwoFactorAuthenticationSection';
+import PageContent from '@/components/shared/PageContent';
+import PageHeader from '@/components/shared/PageHeader';
+import RefreshButton from '@/components/shared/RefreshButton';
+import { usePageTitle } from '@/hooks/usePageTitle';
+
+/**
+ * The security settings page.
+ */
+const SecuritySettings: React.FC = () => {
+ const { t } = useTranslation();
+ const tk = 'pages.main.settings.security.security';
+ usePageTitle(t(`${tk}.PageTitle`));
+ const twoFactorRef = useRef<SectionHandle>(null);
+ const quickUnlockRef = useRef<SectionHandle>(null);
+ const sessionsRef = useRef<SectionHandle>(null);
+ const authLogsRef = useRef<SectionHandle>(null);
+
+ /**
+ * Reload every section at once.
+ */
+ const loadData = useCallback(async (): Promise<void> => {
+ await Promise.all([twoFactorRef.current?.loadData(), quickUnlockRef.current?.loadData(), sessionsRef.current?.loadData(), authLogsRef.current?.loadData()]);
+ }, []);
+
+ useEffect(() => void loadData(), [loadData]);
+
+ return (
+ <>
+ <PageHeader breadcrumbItems={[{ displayName: t(`${tk}.BreadcrumbTitle`) }]} title={t(`${tk}.PageTitle`)} description={t(`${tk}.PageDescription`)} customActions={<RefreshButton onClick={() => void loadData()} buttonText={t(`${tk}.RefreshButton`)} />} />
+
+ <PageContent>
+ <PasswordChangeSection />
+ <TwoFactorAuthenticationSection ref={twoFactorRef} />
+ <QuickVaultUnlockSection ref={quickUnlockRef} />
+ <ActiveSessionsSection ref={sessionsRef} onSessionsChanged={loadData} />
+ <RecentAuthLogsSection ref={authLogsRef} />
+ <DeleteAccountSection />
+ </PageContent>
+ </>
+ );
+};
+
+export default SecuritySettings;