diff --git a/mobile-app/app/(tabs)/(credentials)/index.tsx b/mobile-app/app/(tabs)/(credentials)/index.tsx index 035fcf77b..109e35a3b 100644 --- a/mobile-app/app/(tabs)/(credentials)/index.tsx +++ b/mobile-app/app/(tabs)/(credentials)/index.tsx @@ -89,6 +89,28 @@ export default function CredentialsScreen() { const authContext = useAuth(); const dbContext = useDb(); + /** + * Get the display text for a credential, showing username by default, + * falling back to email only if username is null/undefined + */ + const getCredentialDisplayText = (cred: Credential): string => { + const username = cred.Username ?? ''; + + // Show username if available. + if (username.length > 0) { + return username; + } + + // Show email if username is not available. + const email = cred.Alias?.Email ?? ''; + if (email.length > 0) { + return email; + } + + // Show empty string if neither username nor email is available. + return ''; + }; + const isAuthenticated = authContext.isLoggedIn; const isDatabaseAvailable = dbContext.dbAvailable; @@ -210,16 +232,9 @@ export default function CredentialsScreen() { {item.ServiceName ?? 'Unknown Service'} - {item.Username && ( - - Username: {item.Username} - - )} - {item.Alias?.Email && ( - - Email: {item.Alias.Email} - - )} + + {getCredentialDisplayText(item)} + diff --git a/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor b/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor index 57793f87d..2dab304dc 100644 --- a/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor +++ b/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor @@ -5,7 +5,7 @@
@Obj.Service
-
@Obj.Username
+
@GetDisplayText()
@@ -16,6 +16,28 @@ [Parameter] public required CredentialListEntry Obj { get; set; } + /// + /// Gets the display text for the credential, showing username by default, + /// falling back to email only if username is null/empty. + /// + private string GetDisplayText() + { + // Show username if available + if (!string.IsNullOrEmpty(Obj.Username)) + { + return Obj.Username; + } + + // Show email if username is not available + if (!string.IsNullOrEmpty(Obj.Email)) + { + return Obj.Email; + } + + // Show empty string if neither username nor email is available + return string.Empty; + } + /// /// Navigate to the details page of the credential. ///