Skip to content

Commit

Permalink
handle no public encryptoion key found
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Mamoun98 committed Dec 16, 2024
1 parent 236c029 commit 73f783c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions apps/idos-enclave/src/lib/enclave.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down
14 changes: 7 additions & 7 deletions apps/idos-enclave/src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function App({ store, enclave }: AppProps) {
// Confirm options.
const [origin, setOrigin] = useState<string | null>(null);
const [message, setMessage] = useState<string | null>(null);
const [encryptionPublicKey, setEncryptionUserPublicKey] = useState<string | undefined>();
const [encryptionPublicKey, setEncryptionUserPublicKey] = useState<string>("");
const [humanId] = useState<string | null>(
new URLSearchParams(window.location.search).get("humanId"),
);
Expand All @@ -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), []);

/**
Expand All @@ -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":
Expand Down Expand Up @@ -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 (
<Layout onHeaderClick={resetMethod}>
Expand Down

0 comments on commit 73f783c

Please sign in to comment.