Skip to content

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

Add multi-value field support to mobile app, tweak TOTP editor component (#1473)

Leendert de Borst4f5787a628e8
diff --git a/apps/mobile-app/app/(tabs)/items/add-edit.tsx b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
index c7c660f91..b709b5c27 100644
--- a/apps/mobile-app/app/(tabs)/items/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
@@ -28,6 +28,7 @@ import { FormField } from '@/components/form/FormField';
import { FormSection } from '@/components/form/FormSection';
import { HiddenField } from '@/components/form/HiddenField';
import { ItemNameField, ItemNameFieldRef } from '@/components/form/ItemNameField';
+import { MultiValueField } from '@/components/form/MultiValueField';
import { AttachmentUploader } from '@/components/items/details/AttachmentUploader';
import { TotpEditor } from '@/components/items/details/TotpEditor';
import { ItemTypeSelector } from '@/components/items/ItemTypeSelector';
@@ -83,6 +84,7 @@ export default function AddEditItemScreen(): React.ReactNode {
const [originalAttachmentIds, setOriginalAttachmentIds] = useState<string[]>([]);
const [totpCodes, setTotpCodes] = useState<TotpCode[]>([]);
const [originalTotpCodeIds, setOriginalTotpCodeIds] = useState<string[]>([]);
+ const totpShowAddFormRef = useRef<(() => void) | null>(null);
const [passkeyIds, setPasskeyIds] = useState<string[]>([]);
const [passkeyIdsMarkedForDeletion, setPasskeyIdsMarkedForDeletion] = useState<string[]>([]);
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
@@ -991,13 +993,27 @@ export default function AddEditItemScreen(): React.ReactNode {
label: string,
fieldType: FieldType,
isHidden: boolean,
- _isMultiValue: boolean,
+ isMultiValue: boolean,
onRemove?: () => void
): React.ReactNode => {
const value = fieldValues[fieldKey] || '';
- const stringValue = Array.isArray(value) ? value[0] || '' : value;
const testID = getFieldTestId(fieldKey);
+ // Handle multi-value fields (like URL)
+ if (isMultiValue) {
+ const values = Array.isArray(value) && value.length > 0 ? value : (value ? [value as string] : ['']);
+ return (
+ <MultiValueField
+ label={label}
+ values={values}
+ onValuesChange={(newValues) => handleFieldChange(fieldKey, newValues)}
+ testID={testID}
+ />
+ );
+ }
+
+ const stringValue = Array.isArray(value) ? value[0] || '' : value;
+
switch (fieldType) {
case FieldTypes.Password:
return (
@@ -1268,7 +1284,7 @@ export default function AddEditItemScreen(): React.ReactNode {
/>
{/* Item Name and Primary Fields Section */}
- <FormSection title={t('items.service')}>
+ <FormSection>
<ItemNameField
ref={itemNameRef}
value={item.Name ?? ''}
@@ -1497,11 +1513,19 @@ export default function AddEditItemScreen(): React.ReactNode {
{/* 2FA TOTP Section - only for types with login fields */}
{show2FA && hasLoginFields && (
- <FormSection title={t('common.twoFactorAuthentication')}>
+ <FormSection
+ title={t('common.twoFactorAuthentication')}
+ actions={
+ <RobustPressable onPress={() => totpShowAddFormRef.current?.()} style={{ padding: 4 }}>
+ <MaterialIcons name="add" size={20} color={colors.primary} />
+ </RobustPressable>
+ }
+ >
<TotpEditor
totpCodes={totpCodes}
onTotpCodesChange={setTotpCodes}
originalTotpCodeIds={originalTotpCodeIds}
+ showAddFormRef={totpShowAddFormRef}
/>
</FormSection>
)}
diff --git a/apps/mobile-app/components/form/ItemNameField.tsx b/apps/mobile-app/components/form/ItemNameField.tsx
index b838e47c9..99d5f6309 100644
--- a/apps/mobile-app/components/form/ItemNameField.tsx
+++ b/apps/mobile-app/components/form/ItemNameField.tsx
@@ -169,7 +169,7 @@ export const ItemNameField = forwardRef<ItemNameFieldRef, IItemNameFieldProps>((
return (
<View style={styles.wrapper}>
<Text style={styles.label}>
- {t('items.serviceName')} <Text style={styles.requiredAsterisk}>*</Text>
+ {t('items.itemName')} <Text style={styles.requiredAsterisk}>*</Text>
</Text>
<View style={styles.container}>
<TextInput
@@ -177,7 +177,7 @@ export const ItemNameField = forwardRef<ItemNameFieldRef, IItemNameFieldProps>((
style={styles.input}
value={value}
onChangeText={onChangeText}
- placeholder={t('items.serviceName')}
+ placeholder={t('items.itemName')}
placeholderTextColor={colors.textMuted}
testID="item-name-input"
/>
diff --git a/apps/mobile-app/components/form/MultiValueField.tsx b/apps/mobile-app/components/form/MultiValueField.tsx
new file mode 100644
index 000000000..4373496a1
--- /dev/null
+++ b/apps/mobile-app/components/form/MultiValueField.tsx
@@ -0,0 +1,167 @@
+import { MaterialIcons } from '@expo/vector-icons';
+import React, { useState, useEffect, useRef, useCallback } from 'react';
+import { View, TextInput, StyleSheet, Platform } from 'react-native';
+
+import { useColors } from '@/hooks/useColorScheme';
+
+import { ThemedText } from '@/components/themed/ThemedText';
+import { RobustPressable } from '@/components/ui/RobustPressable';
+
+type MultiValueFieldProps = {
+ label: string;
+ values: string[];
+ onValuesChange: (values: string[]) => void;
+ placeholder?: string;
+ testID?: string;
+};
+
+/**
+ * Multi-value form field component for fields like URLs that support multiple values.
+ * Displays multiple input fields with a "+" button to add more.
+ * Empty values are automatically filtered out when saving, so no explicit remove button is needed.
+ */
+export const MultiValueField: React.FC<MultiValueFieldProps> = ({
+ label,
+ values,
+ onValuesChange,
+ placeholder,
+ testID,
+}) => {
+ const colors = useColors();
+
+ // Track local display values to prevent flickering when adding new fields
+ const [localValues, setLocalValues] = useState<string[]>(values.length > 0 ? values : ['']);
+
+ // Track if we recently added a field (to prevent immediate removal)
+ const recentlyAddedRef = useRef(false);
+ const addTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+
+ // Sync local values with props, but respect the recently added flag
+ useEffect(() => {
+ if (!recentlyAddedRef.current) {
+ setLocalValues(values.length > 0 ? values : ['']);
+ }
+ }, [values]);
+
+ // Cleanup timeout on unmount
+ useEffect(() => {
+ return () => {
+ if (addTimeoutRef.current) {
+ clearTimeout(addTimeoutRef.current);
+ }
+ };
+ }, []);
+
+ /**
+ * Handle value change for a specific index.
+ */
+ const handleValueChange = useCallback((index: number, newValue: string): void => {
+ const newValues = [...localValues];
+ newValues[index] = newValue;
+ setLocalValues(newValues);
+ // Filter empty values for storage, but keep at least empty array
+ onValuesChange(newValues.filter(v => v.trim() !== ''));
+ }, [localValues, onValuesChange]);
+
+ /**
+ * Add a new empty value field.
+ */
+ const handleAddValue = useCallback((): void => {
+ // Set flag to prevent immediate removal of empty field
+ recentlyAddedRef.current = true;
+
+ // Clear any existing timeout
+ if (addTimeoutRef.current) {
+ clearTimeout(addTimeoutRef.current);
+ }
+
+ const newValues = [...localValues, ''];
+ setLocalValues(newValues);
+ onValuesChange(newValues.filter(v => v.trim() !== ''));
+
+ // Allow removal after a delay (gives user time to start typing)
+ addTimeoutRef.current = setTimeout(() => {
+ recentlyAddedRef.current = false;
+ }, 1000);
+ }, [localValues, onValuesChange]);
+
+ const styles = StyleSheet.create({
+ addButton: {
+ alignItems: 'center',
+ borderLeftColor: colors.accentBorder,
+ borderLeftWidth: 1,
+ justifyContent: 'center',
+ paddingHorizontal: 10,
+ paddingVertical: 10,
+ },
+ input: {
+ color: colors.text,
+ flex: 1,
+ fontSize: 16,
+ padding: 10,
+ },
+ inputContainer: {
+ alignItems: 'center',
+ backgroundColor: colors.background,
+ borderColor: colors.accentBorder,
+ borderRadius: 6,
+ borderWidth: 1,
+ flexDirection: 'row',
+ },
+ inputGroup: {
+ marginBottom: 6,
+ },
+ inputLabel: {
+ color: colors.textMuted,
+ fontSize: 12,
+ marginBottom: 4,
+ },
+ valueContainer: {
+ marginBottom: 8,
+ },
+ });
+
+ return (
+ <View style={styles.inputGroup}>
+ <ThemedText style={styles.inputLabel}>{label}</ThemedText>
+ {localValues.map((value, index) => {
+ const isLastInput = index === localValues.length - 1;
+ return (
+ <View key={`${testID || 'multi'}-${index}`} style={styles.valueContainer}>
+ <View style={styles.inputContainer}>
+ <TextInput
+ style={[
+ styles.input,
+ // Add extra right padding on the last input to prevent iOS clear button
+ // from being covered by the add button
+ isLastInput && Platform.OS === 'ios' && { paddingRight: 30 },
+ ]}
+ value={value}
+ onChangeText={(newValue) => handleValueChange(index, newValue)}
+ placeholder={placeholder}
+ placeholderTextColor={colors.textMuted}
+ autoCapitalize="none"
+ autoComplete="off"
+ autoCorrect={false}
+ clearButtonMode={Platform.OS === 'ios' ? 'while-editing' : 'never'}
+ testID={testID ? `${testID}-${index}` : undefined}
+ accessibilityLabel={testID ? `${testID}-${index}` : undefined}
+ />
+ {/* Show add button on the last input */}
+ {isLastInput && (
+ <RobustPressable
+ style={styles.addButton}
+ onPress={handleAddValue}
+ >
+ <MaterialIcons name="add" size={20} color={colors.primary} />
+ </RobustPressable>
+ )}
+ </View>
+ </View>
+ );
+ })}
+ </View>
+ );
+};
+
+export default MultiValueField;
diff --git a/apps/mobile-app/components/items/details/TotpEditor.tsx b/apps/mobile-app/components/items/details/TotpEditor.tsx
index 63bc005b5..f4f20fc5e 100644
--- a/apps/mobile-app/components/items/details/TotpEditor.tsx
+++ b/apps/mobile-app/components/items/details/TotpEditor.tsx
@@ -21,6 +21,10 @@ type TotpEditorProps = {
totpCodes: TotpCode[];
onTotpCodesChange: (totpCodes: TotpCode[]) => void;
originalTotpCodeIds: string[];
+ /** Called when the add button in the header is pressed */
+ onAddPress?: () => void;
+ /** Ref callback to expose the showAddForm function to parent */
+ showAddFormRef?: React.MutableRefObject<(() => void) | null>;
}
/**
@@ -29,7 +33,8 @@ type TotpEditorProps = {
export const TotpEditor: React.FC<TotpEditorProps> = ({
totpCodes,
onTotpCodesChange,
- originalTotpCodeIds
+ originalTotpCodeIds,
+ showAddFormRef
}) => {
const { t } = useTranslation();
const colors = useColors();
@@ -38,6 +43,27 @@ export const TotpEditor: React.FC<TotpEditorProps> = ({
const [formData, setFormData] = useState<TotpFormData>({ name: '', secretKey: '' });
const [formError, setFormError] = useState<string | null>(null);
+ /**
+ * Shows the add form
+ */
+ const showAddForm = (): void => {
+ setFormData({ name: '', secretKey: '' });
+ setFormError(null);
+ setIsAddFormVisible(true);
+ };
+
+ // Expose showAddForm to parent via ref
+ React.useEffect(() => {
+ if (showAddFormRef) {
+ showAddFormRef.current = showAddForm;
+ }
+ return () => {
+ if (showAddFormRef) {
+ showAddFormRef.current = null;
+ }
+ };
+ }, [showAddFormRef]);
+
/**
* Sanitizes the secret key by extracting it from a TOTP URI if needed
*/
@@ -72,15 +98,6 @@ export const TotpEditor: React.FC<TotpEditorProps> = ({
return { secretKey, name: name || 'Authenticator' };
};
- /**
- * Shows the add form
- */
- const showAddForm = (): void => {
- setFormData({ name: '', secretKey: '' });
- setFormError(null);
- setIsAddFormVisible(true);
- };
-
/**
* Hides the add form
*/
@@ -325,20 +342,19 @@ export const TotpEditor: React.FC<TotpEditorProps> = ({
return (
<View>
- <View style={styles.header}>
- {hasActiveTotpCodes && (
- <TouchableOpacity
- style={styles.addButtonCompact}
- onPress={showAddForm}
- >
+ {/* Show inline add button only if parent is not handling it via showAddFormRef */}
+ {!showAddFormRef && !hasActiveTotpCodes && (
+ <TouchableOpacity
+ style={styles.addButton}
+ onPress={showAddForm}
+ >
<Ionicons name="add" size={24} color={colors.background} />
</TouchableOpacity>
- )}
- </View>
+ )}
- {!hasActiveTotpCodes && (
+ {!showAddFormRef && hasActiveTotpCodes && (
<TouchableOpacity
- style={styles.addButton}
+ style={styles.addButtonCompact}
onPress={showAddForm}
>
<Ionicons name="add" size={24} color={colors.background} />
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index 06f8c8c2e..f335c0f61 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -101,112 +101,6 @@
"passwordChangeRequiresOnline": "Password change requires an internet connection. Please try again when online."
}
},
- "credentials": {
- "title": "Credentials",
- "addCredential": "Add Credential",
- "editCredential": "Edit Credential",
- "deleteCredential": "Delete Credential",
- "deleteConfirm": "Are you sure you want to delete this credential? This action cannot be undone.",
- "service": "Service",
- "serviceName": "Service Name",
- "serviceUrl": "Service URL",
- "loginCredentials": "Login credentials",
- "username": "Username",
- "email": "Email",
- "alias": "Alias",
- "metadata": "Metadata",
- "firstName": "First Name",
- "lastName": "Last Name",
- "nickName": "Nick Name",
- "fullName": "Full Name",
- "gender": "Gender",
- "birthDate": "Birth Date",
- "birthDatePlaceholder": "YYYY-MM-DD",
- "notes": "Notes",
- "randomAlias": "Random Alias",
- "manual": "Manual",
- "generateRandomAlias": "Generate Random Alias",
- "clearAliasFields": "Clear Alias Fields",
- "enterFullEmail": "Enter full email address",
- "enterEmailPrefix": "Enter email prefix",
- "useDomainChooser": "Use domain chooser",
- "enterCustomDomain": "Enter custom domain",
- "selectEmailDomain": "Select Email Domain",
- "privateEmailTitle": "Private Email",
- "privateEmailAliasVaultServer": "AliasVault server",
- "privateEmailDescription": "E2E encrypted, fully private.",
- "publicEmailTitle": "Public Temp Email Providers",
- "publicEmailDescription": "Anonymous but limited privacy. Email content is readable by anyone that knows the address.",
- "searchPlaceholder": "Search vault...",
- "noMatchingCredentials": "No matching credentials found",
- "noCredentialsFound": "No credentials found. Create one to get started. Tip: you can also login to the AliasVault web app to import credentials from other password managers.",
- "noPasskeysFound": "No passkeys have been created yet. Passkeys are created by visiting a website that offers passkeys as an authentication method.",
- "noAttachmentsFound": "No credentials with attachments found",
- "recentEmails": "Recent emails",
- "loadingEmails": "Loading emails...",
- "noEmailsYet": "No emails received yet.",
- "offlineEmailsMessage": "You are offline. Please connect to the internet to load your emails.",
- "emailLoadError": "An error occurred while loading emails. Please try again later.",
- "emailUnexpectedError": "An unexpected error occurred while loading emails. Please try again later.",
- "password": "Password",
- "passwordLength": "Password Length",
- "changePasswordComplexity": "Password Settings",
- "includeLowercase": "Lowercase (a-z)",
- "includeUppercase": "Uppercase (A-Z)",
- "includeNumbers": "Numbers (0-9)",
- "includeSpecialChars": "Special Characters (!@#)",
- "avoidAmbiguousChars": "Avoid Ambiguous Characters",
- "deletingCredential": "Deleting credential...",
- "errorLoadingCredentials": "Error loading credentials",
- "vaultSyncFailed": "Vault sync failed",
- "vaultSyncedSuccessfully": "Vault synced successfully",
- "vaultUpToDate": "Vault is up-to-date",
- "offlineMessage": "You are offline. Please connect to the internet to sync your vault.",
- "credentialCreated": "Credential Created!",
- "credentialCreatedMessage": "Your new credential has been added to your vault and is ready to use.",
- "credentialDetails": "Credential Details",
- "emailPreview": "Email Preview",
- "switchBackToBrowser": "Switch back to your browser to continue.",
- "filters": {
- "all": "(All) Credentials",
- "passkeys": "Passkeys",
- "aliases": "Aliases",
- "userpass": "Passwords",
- "attachments": "Attachments"
- },
- "totpCode": "TOTP Code",
- "attachments": "Attachments",
- "deleteAttachment": "Delete",
- "fileSavedTo": "File saved to",
- "previewNotSupported": "Preview not supported",
- "downloadToView": "Download the file to view it",
- "unsavedChanges": {
- "title": "Discard Changes?",
- "message": "You have unsaved changes. Are you sure you want to discard them?",
- "discard": "Discard"
- },
- "toasts": {
- "credentialUpdated": "Credential updated successfully",
- "credentialCreated": "Credential created successfully",
- "credentialDeleted": "Credential deleted successfully",
- "usernameCopied": "Username copied to clipboard",
- "emailCopied": "Email copied to clipboard",
- "passwordCopied": "Password copied to clipboard"
- },
- "createNewAliasFor": "Create new alias for",
- "errors": {
- "loadFailed": "Failed to load credential",
- "saveFailed": "Failed to save credential"
- },
- "contextMenu": {
- "title": "Credential Options",
- "edit": "Edit",
- "delete": "Delete",
- "copyUsername": "Copy Username",
- "copyEmail": "Copy Email",
- "copyPassword": "Copy Password"
- }
- },
"passkeys": {
"passkey": "Passkey",
"helpText": "Passkeys are created on the website when prompted. They cannot be manually edited. To remove this passkey, you can delete it from this credential.",
@@ -488,6 +382,7 @@
"untitled": "Untitled",
"name": "Name",
"url": "URL",
+ "itemName": "Name",
"service": "Service",
"serviceName": "Service Name",
"serviceUrl": "Service URL",