Skip to content

Commit

Permalink
fixing guards to make sure code doesn't throw if executed server-side…
Browse files Browse the repository at this point in the history
… (SSR) by frameworks, closes #2
  • Loading branch information
getify committed Mar 17, 2024
1 parent 660ad5c commit 531d37a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ await loadScript(import.meta.resolve(`./external/libsodium-wrappers.js`));
// ********************************

function loadScript(filepath) {
if (typeof document == "undefined") return;
var loadComplete = null;
var pr = new Promise(res => loadComplete = res);
var script = document.createElement("script");
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const publicKeyAlgorithmsLookup = Object.fromEntries(
const credentialTypeKey = Symbol("credential-type");
const resetAbortReason = Symbol("reset-abort");
const supportsWebAuthn = (
navigator.credentials &&
typeof navigator != "undefined" &&
typeof navigator.credentials != "undefined" &&
typeof navigator.credentials.create != "undefined" &&
typeof navigator.credentials.get != "undefined" &&
typeof PublicKeyCredential != "undefined" &&
Expand All @@ -87,6 +88,7 @@ const supportsWebAuthn = (
// Re: https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential/isConditionalMediationAvailable
// Also: https://web.dev/articles/passkey-form-autofill
const supportsConditionalMediation = (
supportsWebAuthn &&
typeof PublicKeyCredential.isConditionalMediationAvailable != "undefined" &&
(await PublicKeyCredential.isConditionalMediationAvailable())
);
Expand Down

0 comments on commit 531d37a

Please sign in to comment.