Skip to content

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

Refactor custom field logic to match between clients (#1404)

Leendert de Borst4f57b8fdeef8
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
index c31f7d599..a7e2703f4 100644
--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts
@@ -261,7 +261,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.URL,
Value: serviceUrl,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
}
@@ -273,7 +275,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Text,
Value: result.customUsername,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
}
@@ -285,7 +289,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Email,
Value: result.customEmail,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
}
@@ -297,7 +303,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Password,
Value: result.customPassword,
IsHidden: true,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: true
});
}
@@ -346,7 +354,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.URL,
Value: serviceUrl,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
}
@@ -357,7 +367,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Text,
Value: identity.nickName,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
// Add email
@@ -367,7 +379,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Email,
Value: `${identity.emailPrefix}@${domain}`,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
// Add password
@@ -377,7 +391,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Password,
Value: password,
IsHidden: true,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: true
});
// Add alias fields
@@ -387,7 +403,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Text,
Value: identity.firstName,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
fields.push({
@@ -396,7 +414,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Text,
Value: identity.lastName,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
fields.push({
@@ -405,7 +425,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Date,
Value: IdentityHelperUtils.normalizeBirthDate(identity.birthDate.toISOString()),
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
fields.push({
@@ -414,7 +436,9 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]
FieldType: FieldTypes.Text,
Value: identity.gender,
IsHidden: false,
- DisplayOrder: displayOrder++
+ DisplayOrder: displayOrder++,
+ IsCustomField: false,
+ EnableHistory: false
});
newItem = {
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx
index 0362772b9..b319116c4 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx
@@ -39,13 +39,12 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId, hideLabel = fals
const [historyCount, setHistoryCount] = useState<number>(0);
/* Get translated label for this field. System fields use fieldLabels.* translations, custom fields use their stored label */
- const label = field.FieldKey.startsWith('custom_')
+ const label = field.IsCustomField
? (field.Label || field.FieldKey)
: t(`fieldLabels.${field.FieldKey}`, { defaultValue: field.FieldKey });
- // Check if this field supports history
- const systemField = !field.FieldKey.startsWith('custom_') ? getSystemField(field.FieldKey) : null;
- const hasHistoryEnabled = systemField?.EnableHistory === true;
+ // Check if this field has history enabled
+ const hasHistoryEnabled = field.EnableHistory === true;
// Check if there's actual history available
useEffect(() => {
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
index 79650f9ea..86a0d69a8 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/credentials/ItemAddEdit.tsx
@@ -400,8 +400,8 @@ const ItemAddEdit: React.FC = () => {
// Track fields that have values so they stay visible even if cleared
fieldsWithValues.add(field.FieldKey);
- // If field key starts with "custom_", it's a custom field
- if (field.FieldKey.startsWith('custom_')) {
+ // Check if it's a custom field using the IsCustomField property
+ if (field.IsCustomField) {
existingCustomFields.push({
tempId: field.FieldKey,
label: field.Label,
@@ -596,7 +596,9 @@ const ItemAddEdit: React.FC = () => {
FieldType: systemField.FieldType,
Value: value,
IsHidden: systemField.IsHidden,
- DisplayOrder: systemField.DefaultDisplayOrder
+ DisplayOrder: systemField.DefaultDisplayOrder,
+ IsCustomField: false,
+ EnableHistory: systemField.EnableHistory
});
}
});
@@ -613,7 +615,9 @@ const ItemAddEdit: React.FC = () => {
FieldType: customField.fieldType,
Value: value,
IsHidden: customField.isHidden,
- DisplayOrder: customField.displayOrder
+ DisplayOrder: customField.displayOrder,
+ IsCustomField: true,
+ EnableHistory: false // Custom fields don't have history enabled by default
});
}
});
@@ -716,7 +720,10 @@ const ItemAddEdit: React.FC = () => {
* Add custom field handler.
*/
const handleAddCustomField = useCallback((label: string, fieldType: FieldType) => {
- const tempId = `custom_${crypto.randomUUID()}`;
+ /**
+ * Custom fields are identified by having FieldDefinitionId set (not FieldKey).
+ */
+ const tempId = crypto.randomUUID();
const newField: CustomFieldDefinition = {
tempId,
label,
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx b/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx
index 557eff6da..a62885218 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/passkeys/PasskeyCreate.tsx
@@ -325,8 +325,8 @@ const PasskeyCreate: React.FC = () => {
Logo: faviconLogo ?? existingItem.Logo,
Fields: [
...(existingItem.Fields || []).filter((f) => f.FieldKey !== FieldKey.LoginUrl && f.FieldKey !== FieldKey.LoginUsername),
- { FieldKey: FieldKey.LoginUrl, Label: 'URL', FieldType: FieldTypes.URL, Value: request.origin, IsHidden: false, DisplayOrder: 0 },
- { FieldKey: FieldKey.LoginUsername, Label: 'Username', FieldType: FieldTypes.Text, Value: request.publicKey.user.name, IsHidden: false, DisplayOrder: 1 }
+ { FieldKey: FieldKey.LoginUrl, Label: 'URL', FieldType: FieldTypes.URL, Value: request.origin, IsHidden: false, DisplayOrder: 0, IsCustomField: false, EnableHistory: false },
+ { FieldKey: FieldKey.LoginUsername, Label: 'Username', FieldType: FieldTypes.Text, Value: request.publicKey.user.name, IsHidden: false, DisplayOrder: 1, IsCustomField: false, EnableHistory: false }
]
},
[],
@@ -398,8 +398,8 @@ const PasskeyCreate: React.FC = () => {
ItemType: ItemTypes.Login,
Logo: faviconLogo,
Fields: [
- { FieldKey: FieldKey.LoginUrl, Label: 'URL', FieldType: FieldTypes.URL, Value: request.origin, IsHidden: false, DisplayOrder: 0 },
- { FieldKey: FieldKey.LoginUsername, Label: 'Username', FieldType: FieldTypes.Text, Value: request.publicKey.user.name, IsHidden: false, DisplayOrder: 1 }
+ { FieldKey: FieldKey.LoginUrl, Label: 'URL', FieldType: FieldTypes.URL, Value: request.origin, IsHidden: false, DisplayOrder: 0, IsCustomField: false, EnableHistory: false },
+ { FieldKey: FieldKey.LoginUsername, Label: 'Username', FieldType: FieldTypes.Text, Value: request.publicKey.user.name, IsHidden: false, DisplayOrder: 1, IsCustomField: false, EnableHistory: false }
],
CreatedAt: new Date().toISOString(),
UpdatedAt: new Date().toISOString()
diff --git a/apps/browser-extension/src/utils/db/mappers/FieldMapper.ts b/apps/browser-extension/src/utils/db/mappers/FieldMapper.ts
index d50fa5c19..b0bbfc7f2 100644
--- a/apps/browser-extension/src/utils/db/mappers/FieldMapper.ts
+++ b/apps/browser-extension/src/utils/db/mappers/FieldMapper.ts
@@ -11,6 +11,7 @@ export type FieldRow = {
CustomLabel: string | null;
CustomFieldType: string | null;
CustomIsHidden: number | null;
+ CustomEnableHistory: number | null;
Value: string;
DisplayOrder: number;
}
@@ -26,6 +27,8 @@ export type ProcessedField = {
IsHidden: number;
Value: string;
DisplayOrder: number;
+ IsCustomField: boolean;
+ EnableHistory: boolean;
}
/**
@@ -71,7 +74,9 @@ export class FieldMapper {
FieldType: field.FieldType as FieldType,
Value: '', // Will be set below
IsHidden: field.IsHidden === 1,
- DisplayOrder: field.DisplayOrder
+ DisplayOrder: field.DisplayOrder,
+ IsCustomField: field.IsCustomField,
+ EnableHistory: field.EnableHistory
});
}
}
@@ -111,18 +116,22 @@ export class FieldMapper {
FieldType: systemField?.FieldType || FieldTypes.Text,
IsHidden: systemField?.IsHidden ? 1 : 0,
Value: row.Value,
- DisplayOrder: row.DisplayOrder
+ DisplayOrder: row.DisplayOrder,
+ IsCustomField: false,
+ EnableHistory: systemField?.EnableHistory ?? false
};
} else {
// Custom field: has FieldDefinitionId, get metadata from FieldDefinitions
return {
ItemId: row.ItemId,
- FieldKey: row.FieldDefinitionId || '', // Use FieldDefinitionId as the key for custom fields
+ FieldKey: row.FieldDefinitionId || '', // Use FieldDefinitionId (UUID) as the key for custom fields
Label: row.CustomLabel || '',
FieldType: row.CustomFieldType || FieldTypes.Text,
IsHidden: row.CustomIsHidden || 0,
Value: row.Value,
- DisplayOrder: row.DisplayOrder
+ DisplayOrder: row.DisplayOrder,
+ IsCustomField: true,
+ EnableHistory: row.CustomEnableHistory === 1
};
}
}
@@ -141,6 +150,8 @@ export class FieldMapper {
FieldType: string;
IsHidden: number;
DisplayOrder: number;
+ IsCustomField: boolean;
+ EnableHistory: boolean;
}>();
for (const row of rows) {
@@ -162,7 +173,9 @@ export class FieldMapper {
Label: row.FieldKey, // Use FieldKey as label; UI layer translates via fieldLabels.*
FieldType: systemField?.FieldType || FieldTypes.Text,
IsHidden: systemField?.IsHidden ? 1 : 0,
- DisplayOrder: row.DisplayOrder
+ DisplayOrder: row.DisplayOrder,
+ IsCustomField: false,
+ EnableHistory: systemField?.EnableHistory ?? false
});
} else {
// Custom field
@@ -171,7 +184,9 @@ export class FieldMapper {
Label: row.CustomLabel || '',
FieldType: row.CustomFieldType || FieldTypes.Text,
IsHidden: row.CustomIsHidden || 0,
- DisplayOrder: row.DisplayOrder
+ DisplayOrder: row.DisplayOrder,
+ IsCustomField: true,
+ EnableHistory: row.CustomEnableHistory === 1
});
}
}
@@ -184,7 +199,9 @@ export class FieldMapper {
...metadata,
FieldType: metadata.FieldType as FieldType,
Value: values.length === 1 ? values[0] : values,
- IsHidden: metadata.IsHidden === 1
+ IsHidden: metadata.IsHidden === 1,
+ IsCustomField: metadata.IsCustomField,
+ EnableHistory: metadata.EnableHistory
};
});
}
diff --git a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts b/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
index 712eb5601..f26dffbd3 100644
--- a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
+++ b/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
@@ -86,6 +86,7 @@ export class ItemQueries {
fd.Label as CustomLabel,
fd.FieldType as CustomFieldType,
fd.IsHidden as CustomIsHidden,
+ fd.EnableHistory as CustomEnableHistory,
fv.Value,
fv.Weight as DisplayOrder
FROM FieldValues fv
@@ -105,6 +106,7 @@ export class ItemQueries {
fd.Label as CustomLabel,
fd.FieldType as CustomFieldType,
fd.IsHidden as CustomIsHidden,
+ fd.EnableHistory as CustomEnableHistory,
fv.Value,
fv.Weight as DisplayOrder
FROM FieldValues fv
diff --git a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
index d87679a69..aba6b571f 100644
--- a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
@@ -1,5 +1,5 @@
import type { Item, ItemField, Attachment, TotpCode, FieldHistory } from '@/utils/dist/core/models/vault';
-import { FieldKey, getSystemField, MAX_FIELD_HISTORY_RECORDS } from '@/utils/dist/core/models/vault';
+import { FieldKey, MAX_FIELD_HISTORY_RECORDS } from '@/utils/dist/core/models/vault';
import { BaseRepository, type IDatabaseClient } from '../BaseRepository';
import { FieldMapper, type FieldRow } from '../mappers/FieldMapper';
@@ -407,11 +407,10 @@ export class ItemRepository extends BaseRepository {
continue;
}
- const isCustomField = field.FieldKey.startsWith('custom_');
let fieldDefinitionId = null;
// For custom fields, create or get FieldDefinition
- if (isCustomField) {
+ if (field.IsCustomField) {
fieldDefinitionId = this.ensureFieldDefinition(field, itemType, currentDateTime);
}
@@ -427,7 +426,7 @@ export class ItemRepository extends BaseRepository {
this.generateId(),
itemId,
fieldDefinitionId,
- isCustomField ? null : field.FieldKey,
+ field.IsCustomField ? null : field.FieldKey,
value,
field.DisplayOrder ?? 0,
currentDateTime,
@@ -502,10 +501,9 @@ export class ItemRepository extends BaseRepository {
continue;
}
- const isCustomField = field.FieldKey.startsWith('custom_');
let fieldDefinitionId = null;
- if (isCustomField) {
+ if (field.IsCustomField) {
fieldDefinitionId = this.ensureOrUpdateFieldDefinition(field, item.ItemType, currentDateTime);
}
@@ -536,7 +534,7 @@ export class ItemRepository extends BaseRepository {
this.generateId(),
item.Id,
fieldDefinitionId,
- isCustomField ? null : field.FieldKey,
+ field.IsCustomField ? null : field.FieldKey,
value,
field.DisplayOrder ?? 0,
currentDateTime,
@@ -620,13 +618,12 @@ export class ItemRepository extends BaseRepository {
}
for (const newField of newFields) {
- // Skip custom fields
- if (newField.FieldKey.startsWith('custom_')) {
- continue;
- }
-
- const systemField = getSystemField(newField.FieldKey);
- if (!systemField || !systemField.EnableHistory) {
+ /**
+ * Check if history tracking is enabled for this field.
+ * EnableHistory comes from SystemFieldRegistry for system fields,
+ * or from the FieldDefinitions table for custom fields.
+ */
+ if (!newField.EnableHistory) {
continue;
}
diff --git a/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
index 546d5615a..e5d3247f4 100644
--- a/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/core/models/vault/index.d.ts
@@ -282,7 +282,9 @@ type Item = {
UpdatedAt: string;
};
/**
- * Field value within an item
+ * Field value within an item.
+ * For system fields: FieldKey is the system field key (e.g., "login.username"), IsCustomField is false.
+ * For custom fields: FieldKey is the FieldDefinitionId (UUID), IsCustomField is true.
*/
type ItemField = {
FieldKey: string;
@@ -291,6 +293,18 @@ type ItemField = {
Value: string | string[];
IsHidden: boolean;
DisplayOrder: number;
+ /**
+ * Whether this is a custom (user-defined) field.
+ * Custom fields have their metadata stored in FieldDefinitions table.
+ * System fields have their metadata defined in code (SystemFieldRegistry).
+ */
+ IsCustomField: boolean;
+ /**
+ * Whether history tracking is enabled for this field.
+ * For system fields, this comes from SystemFieldRegistry.
+ * For custom fields, this comes from the FieldDefinition record.
+ */
+ EnableHistory: boolean;
};
/**
* Field types for rendering and validation.
diff --git a/apps/mobile-app/utils/dist/core/models/vault/index.d.ts b/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
index 546d5615a..e5d3247f4 100644
--- a/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
+++ b/apps/mobile-app/utils/dist/core/models/vault/index.d.ts
@@ -282,7 +282,9 @@ type Item = {
UpdatedAt: string;
};
/**
- * Field value within an item
+ * Field value within an item.
+ * For system fields: FieldKey is the system field key (e.g., "login.username"), IsCustomField is false.
+ * For custom fields: FieldKey is the FieldDefinitionId (UUID), IsCustomField is true.
*/
type ItemField = {
FieldKey: string;
@@ -291,6 +293,18 @@ type ItemField = {
Value: string | string[];
IsHidden: boolean;
DisplayOrder: number;
+ /**
+ * Whether this is a custom (user-defined) field.
+ * Custom fields have their metadata stored in FieldDefinitions table.
+ * System fields have their metadata defined in code (SystemFieldRegistry).
+ */
+ IsCustomField: boolean;
+ /**
+ * Whether history tracking is enabled for this field.
+ * For system fields, this comes from SystemFieldRegistry.
+ * For custom fields, this comes from the FieldDefinition record.
+ */
+ EnableHistory: boolean;
};
/**
* Field types for rendering and validation.
diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
index b63a2c79d..24cf953ce 100644
--- a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
@@ -76,8 +76,14 @@
/// </summary>
private string GetLabel()
{
+ // For custom fields, use the Label property directly
+ if (Field.IsCustomField)
+ {
+ return !string.IsNullOrEmpty(Field.Label) ? Field.Label : FormatFieldName(Field.FieldKey);
+ }
+
// Try to get localized label for system field
- if (!string.IsNullOrEmpty(Field.FieldKey) && !Field.FieldKey.StartsWith("custom_"))
+ if (!string.IsNullOrEmpty(Field.FieldKey))
{
// Convert field key to localization key format
// e.g., "login.username" -> "FieldLabel_login_username"
diff --git a/apps/server/AliasVault.Client/Main/Models/DisplayField.cs b/apps/server/AliasVault.Client/Main/Models/DisplayField.cs
index 888769f39..47e2a38b6 100644
--- a/apps/server/AliasVault.Client/Main/Models/DisplayField.cs
+++ b/apps/server/AliasVault.Client/Main/Models/DisplayField.cs
@@ -24,11 +24,23 @@ public class DisplayField
/// </summary>
public string? FieldDefinitionId { get; set; }
+ /// <summary>
+ /// Gets or sets the label for this field.
+ /// For system fields, this is the field key (UI layer translates).
+ /// For custom fields, this is the user-defined label from FieldDefinition.
+ /// </summary>
+ public string Label { get; set; } = string.Empty;
+
/// <summary>
/// Gets or sets the field type for rendering (Text, Password, Email, URL, Date, etc.).
/// </summary>
public string FieldType { get; set; } = "Text";
+ /// <summary>
+ /// Gets or sets a value indicating whether this is a custom field.
+ /// </summary>
+ public bool IsCustomField { get; set; }
+
/// <summary>
/// Gets or sets the field value.
/// </summary>
diff --git a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs b/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
index 036b13d80..618908765 100644
--- a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
+++ b/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
@@ -315,11 +315,18 @@ public sealed class ItemEdit
// Add custom fields
foreach (var customField in CustomFields.Where(cf => !string.IsNullOrEmpty(cf.Value)))
{
- // For new custom fields (TempId set, FieldDefinitionId is empty), create a new FieldDefinition
+ // For new custom fields (TempId set, FieldDefinitionId is empty), create a new FieldDefinition.
+ // The FieldDefinition.Id is a plain GUID - no prefix needed.
+ // Custom fields are identified by having FieldDefinitionId set (not FieldKey).
if (customField.FieldDefinitionId == Guid.Empty && !string.IsNullOrEmpty(customField.TempId))
{
var now = DateTime.UtcNow;
- var fieldDefinitionId = Guid.NewGuid();
+
+ // TempId is a plain GUID string
+ var fieldDefinitionId = Guid.TryParse(customField.TempId, out var parsedGuid)
+ ? parsedGuid
+ : Guid.NewGuid();
+
var fieldDefinition = new FieldDefinition
{
Id = fieldDefinitionId,
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
index c027103b2..556d80272 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
@@ -618,7 +618,9 @@ else
/// </summary>
private void AddCustomField((string Label, string FieldType) args)
{
- var tempId = $"custom_{Guid.NewGuid()}";
+ // Use a plain GUID for the TempId - no prefix needed.
+ // Custom fields are identified by having FieldDefinitionId set (not FieldKey).
+ var tempId = Guid.NewGuid().ToString();
Obj.CustomFields.Add(new CustomFieldEdit
{
TempId = tempId,
diff --git a/apps/server/AliasVault.Client/Main/Utilities/FieldGrouper.cs b/apps/server/AliasVault.Client/Main/Utilities/FieldGrouper.cs
index e08df12a4..168e77ad1 100644
--- a/apps/server/AliasVault.Client/Main/Utilities/FieldGrouper.cs
+++ b/apps/server/AliasVault.Client/Main/Utilities/FieldGrouper.cs
@@ -101,19 +101,35 @@ public static class FieldGrouper
// Determine category from field key prefix
var category = GetCategoryFromFieldKey(fieldValue.FieldKey);
+ // Check if this is a custom field (has FieldDefinitionId but no FieldKey)
+ var isCustomField = fieldValue.FieldDefinitionId.HasValue && string.IsNullOrEmpty(fieldValue.FieldKey);
+
// Get system field definition if available
var systemField = !string.IsNullOrEmpty(fieldValue.FieldKey)
? SystemFieldRegistry.GetSystemField(fieldValue.FieldKey)
: null;
+ // For custom fields, get label and type from FieldDefinition
+ var fieldDefinition = fieldValue.FieldDefinition;
+
return new DisplayField
{
- FieldKey = fieldValue.FieldKey ?? string.Empty,
+ FieldKey = fieldValue.FieldKey ?? fieldValue.FieldDefinitionId?.ToString() ?? string.Empty,
FieldDefinitionId = fieldValue.FieldDefinitionId?.ToString(),
- FieldType = systemField?.FieldType ?? "Text",
+ Label = isCustomField
+ ? fieldDefinition?.Label ?? string.Empty
+ : fieldValue.FieldKey ?? string.Empty,
+ FieldType = isCustomField
+ ? fieldDefinition?.FieldType ?? "Text"
+ : systemField?.FieldType ?? "Text",
+ IsCustomField = isCustomField,
Value = fieldValue.Value,
- IsHidden = systemField?.IsHidden ?? false,
- EnableHistory = systemField?.EnableHistory ?? false,
+ IsHidden = isCustomField
+ ? fieldDefinition?.IsHidden ?? false
+ : systemField?.IsHidden ?? false,
+ EnableHistory = isCustomField
+ ? fieldDefinition?.EnableHistory ?? false
+ : systemField?.EnableHistory ?? false,
DisplayOrder = systemField?.DefaultDisplayOrder ?? fieldValue.Weight,
Category = category,
};
diff --git a/core/models/src/vault/Item.ts b/core/models/src/vault/Item.ts
index 560f7e405..29f63f563 100644
--- a/core/models/src/vault/Item.ts
+++ b/core/models/src/vault/Item.ts
@@ -33,7 +33,9 @@ export type Item = {
}
/**
- * Field value within an item
+ * Field value within an item.
+ * For system fields: FieldKey is the system field key (e.g., "login.username"), IsCustomField is false.
+ * For custom fields: FieldKey is the FieldDefinitionId (UUID), IsCustomField is true.
*/
export type ItemField = {
FieldKey: string;
@@ -42,6 +44,18 @@ export type ItemField = {
Value: string | string[];
IsHidden: boolean;
DisplayOrder: number;
+ /**
+ * Whether this is a custom (user-defined) field.
+ * Custom fields have their metadata stored in FieldDefinitions table.
+ * System fields have their metadata defined in code (SystemFieldRegistry).
+ */
+ IsCustomField: boolean;
+ /**
+ * Whether history tracking is enabled for this field.
+ * For system fields, this comes from SystemFieldRegistry.
+ * For custom fields, this comes from the FieldDefinition record.
+ */
+ EnableHistory: boolean;
}
/**