Streamline passkey display name creation (#520)

This commit is contained in:
Leendert de Borst
2025-10-26 20:51:52 +01:00
parent ad086689dd
commit 71ddbbe3d2
4 changed files with 12 additions and 5 deletions

View File

@@ -34,7 +34,7 @@ const PasskeyCreate: React.FC = () => {
const webApi = useWebApi();
const { executeVaultMutation, isLoading: isMutating, syncStatus } = useVaultMutate();
const [request, setRequest] = useState<PendingPasskeyCreateRequest | null>(null);
const [displayName, setDisplayName] = useState('My Passkey');
const [displayName, setDisplayName] = useState('');
const [error, setError] = useState<string | null>(null);
const { isLocked } = useVaultLockRedirect();
const [existingPasskeys, setExistingPasskeys] = useState<Array<Passkey & { Username?: string | null; ServiceName?: string | null }>>([]);
@@ -71,9 +71,12 @@ const PasskeyCreate: React.FC = () => {
if (data && data.type === 'create') {
setRequest(data);
if (data.publicKey?.user?.displayName) {
setDisplayName(data.publicKey.user.displayName);
}
/**
* Set default displayName: use rp.name if available, otherwise use rpId
* This aligns with iOS/Android behavior
*/
const defaultName = data.publicKey?.rp?.name || data.publicKey?.rp?.id || 'Passkey';
setDisplayName(defaultName);
// Check for existing passkeys for this RP ID and user
if (dbContext.sqliteClient && data.publicKey?.rp?.id) {

View File

@@ -130,7 +130,7 @@ class PasskeyFormFragment : Fragment() {
headerTitle.text = getString(R.string.create_passkey_title)
headerSubtitle.visibility = View.GONE
infoExplanationText.text = getString(R.string.passkey_create_explanation)
displayNameInput.setText(viewModel.rpId)
displayNameInput.setText(viewModel.rpName ?: viewModel.rpId)
saveButton.text = getString(R.string.passkey_create_button)
}

View File

@@ -75,6 +75,7 @@ class PasskeyRegistrationActivity : FragmentActivity() {
// Extract RP info
val rpObj = requestObj.optJSONObject("rp")
viewModel.rpId = rpObj?.optString("id") ?: ""
viewModel.rpName = rpObj?.optString("name")?.takeIf { it.isNotEmpty() }
// Extract user info
val userObj = requestObj.optJSONObject("user")

View File

@@ -20,6 +20,9 @@ class PasskeyRegistrationViewModel : ViewModel() {
/** The relying party identifier. */
var rpId: String = ""
/** The relying party name (optional, from rp.name in the request). */
var rpName: String? = null
/** The username for the passkey. */
var userName: String? = null