From 5c37dd43c5873891d38d4d241267f224e18d75be Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 25 Oct 2026 18:02:45 +0100 Subject: [PATCH] fix(native): hide passkeys in the app through usePasskeys The flag in useAccountSettings grew the identical destructuring in both account views past the duplication threshold; the shared passkeys hook already decides when its card is hidden, so the app check lives there now. --- client/src/components/Settings/AccountTab.tsx | 5 ++--- client/src/components/Settings/useAccountSettings.ts | 6 ------ client/src/components/Settings/usePasskeys.ts | 7 +++++-- client/src/mobile/screens/settings/MSettingsAccount.tsx | 3 +-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/client/src/components/Settings/AccountTab.tsx b/client/src/components/Settings/AccountTab.tsx index 130ebf27b..39d383389 100644 --- a/client/src/components/Settings/AccountTab.tsx +++ b/client/src/components/Settings/AccountTab.tsx @@ -55,7 +55,6 @@ export default function AccountTab(): React.ReactElement { backupCodesText, mfaRequiredByPolicy, oidcIssuer, - passkeysAvailable, dismissBackupCodes, copyBackupCodes, downloadBackupCodes, @@ -363,8 +362,8 @@ export default function AccountTab(): React.ReactElement { - {/* Passkeys: managed in the browser, not in the native app (see useAccountSettings). */} - {passkeysAvailable && } + {/* Passkeys */} + {/* Delete Account Blocked */} diff --git a/client/src/components/Settings/useAccountSettings.ts b/client/src/components/Settings/useAccountSettings.ts index 31a3b2ecc..1c915a702 100644 --- a/client/src/components/Settings/useAccountSettings.ts +++ b/client/src/components/Settings/useAccountSettings.ts @@ -3,7 +3,6 @@ import React, { useEffect, useRef, useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router'; import { adminApi, authApi } from '../../api/client'; import { useTranslation } from '../../i18n'; -import { isNativeApp } from '../../native/platform'; import { useAuthStore } from '../../store/authStore'; import { getApiErrorMessage, type UserWithOidc } from '../../types'; import { downloadBlob } from '../../utils/fileDownload'; @@ -272,10 +271,6 @@ export function useAccountSettings({ avatarRemoveErrorKey, ignoreEmptyBackupCode }; const oidcIssuer = (user as UserWithOidc)?.oidc_issuer; - // Passkeys stay in the browser: WebAuthn in the native app's WebView needs a - // domain association no build can have for every server, so they are managed - // there (signing in with one works through the browser hand-off too). - const passkeysAvailable = !isNativeApp(); return { user, @@ -308,7 +303,6 @@ export function useAccountSettings({ avatarRemoveErrorKey, ignoreEmptyBackupCode backupCodesText, mfaRequiredByPolicy, oidcIssuer, - passkeysAvailable, dismissBackupCodes, copyBackupCodes, downloadBackupCodes, diff --git a/client/src/components/Settings/usePasskeys.ts b/client/src/components/Settings/usePasskeys.ts index 89d89cc68..bb8e5b6b1 100644 --- a/client/src/components/Settings/usePasskeys.ts +++ b/client/src/components/Settings/usePasskeys.ts @@ -2,6 +2,7 @@ import { startRegistration } from '@simplewebauthn/browser'; import { useEffect, useState } from 'react'; import { authApi, type PasskeyCredential } from '../../api/client'; import { useTranslation } from '../../i18n'; +import { isNativeApp } from '../../native/platform'; import { getApiErrorMessage } from '../../types'; import { useToast } from '../shared/Toast'; @@ -24,7 +25,9 @@ export function isWebauthnAbort(err: unknown): boolean { * list, add (a password step-up, then the WebAuthn ceremony), rename, and delete * (password step-up). Adding needs the instance toggle on AND a usable RP ID; the * list stays reachable when the feature is later switched off so users can clean up. - * `hidden` tells a view to render nothing: in demo mode, or when there is nothing to show. + * `hidden` tells a view to render nothing: in demo mode, when there is nothing to show, or + * inside the native app, whose WebView cannot run WebAuthn for every server's domain (the + * passkeys are managed in the browser there, and signing in with one goes through it too). */ export function usePasskeys({ demoMode = false }: { demoMode?: boolean } = {}) { const { t } = useTranslation(); @@ -68,7 +71,7 @@ export function usePasskeys({ demoMode = false }: { demoMode?: boolean } = {}) { const canAdd = enabled && configured; // Nothing to show: feature off and the user has no credentials to manage. const nothingToShow = !loading && !enabled && creds.length === 0; - const hidden = demoMode || nothingToShow; + const hidden = demoMode || nothingToShow || isNativeApp(); // The toggle is on but no usable RP ID resolves, so adding stays off. const notConfigured = enabled && !configured; diff --git a/client/src/mobile/screens/settings/MSettingsAccount.tsx b/client/src/mobile/screens/settings/MSettingsAccount.tsx index 85ae7bab6..9e974cff2 100644 --- a/client/src/mobile/screens/settings/MSettingsAccount.tsx +++ b/client/src/mobile/screens/settings/MSettingsAccount.tsx @@ -61,7 +61,6 @@ export default function MSettingsAccount() { backupCodesText, mfaRequiredByPolicy, oidcIssuer, - passkeysAvailable, dismissBackupCodes, copyBackupCodes, downloadBackupCodes, @@ -291,7 +290,7 @@ export default function MSettingsAccount() { - {passkeysAvailable && } +