diff --git a/apps/idos-enclave/src/lib/enclave.js b/apps/idos-enclave/src/lib/enclave.js index 06444f734..2b7afeb81 100644 --- a/apps/idos-enclave/src/lib/enclave.js +++ b/apps/idos-enclave/src/lib/enclave.js @@ -125,12 +125,13 @@ export class Enclave { try { if (storedCredentialId) { ({ password, credentialId } = await getWebAuthnCredential(storedCredentialId)); - } else if (preferredAuthMethod) { - ({ password, duration } = await this.#openDialog(preferredAuthMethod)); } else { - ({ password, duration, credentialId } = await this.#openDialog("auth", { - expectedUserEncryptionPublicKey: this.expectedUserEncryptionPublicKey, - })); + ({ password, duration, credentialId } = await this.#openDialog( + preferredAuthMethod || "auth", + { + expectedUserEncryptionPublicKey: this.expectedUserEncryptionPublicKey, + }, + )); } } catch (e) { return reject(e); @@ -369,7 +370,7 @@ export class Enclave { const response = await this[requestName](...paramBuilder()); event.ports[0].postMessage({ result: response }); } catch (error) { - console.warn("catch", error); + console.error("catch", error); event.ports[0].postMessage({ error }); } finally { this.unlockButton.style.display = "none"; diff --git a/apps/idos-enclave/src/pages/App.tsx b/apps/idos-enclave/src/pages/App.tsx index cce6f22f2..eeda3f203 100644 --- a/apps/idos-enclave/src/pages/App.tsx +++ b/apps/idos-enclave/src/pages/App.tsx @@ -63,7 +63,7 @@ export function App({ store, enclave }: AppProps) { // Confirm options. const [origin, setOrigin] = useState(null); const [message, setMessage] = useState(null); - const [encryptionPublicKey, setEncryptionUserPublicKey] = useState(); + const [encryptionPublicKey, setEncryptionUserPublicKey] = useState(""); const [humanId] = useState( new URLSearchParams(window.location.search).get("humanId"), ); @@ -88,11 +88,6 @@ export function App({ store, enclave }: AppProps) { } }, [theme]); - useEffect(() => { - if (mode === "new" || !responsePort.current) return; - if (!encryptionPublicKey) onError("Can’t find a public encryption key for this user"); - }, [mode, encryptionPublicKey, responsePort.current]); - const resetMethod = useCallback(() => setMethod(null), []); /** @@ -107,11 +102,11 @@ export function App({ store, enclave }: AppProps) { throw new Error(`Unexpected request from parent: ${requestData.intent}`); responsePort.current = ports[0]; + setEncryptionUserPublicKey(event.data.message.expectedUserEncryptionPublicKey); switch (requestData.intent) { case "auth": setMethod(null); - setEncryptionUserPublicKey(event.data.message.expectedUserEncryptionPublicKey); break; case "passkey": @@ -181,6 +176,11 @@ export function App({ store, enclave }: AppProps) { mode, }; + useEffect(() => { + if (mode === "new" || !responsePort.current) return; + if (!encryptionPublicKey) onError("Can’t find a public encryption key for this user"); + }, [mode, encryptionPublicKey, responsePort.current]); + if (confirm && message) { return (