Skip to content

Commit

Permalink
Explicit null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Keroosha committed Jun 4, 2024
1 parent ddde885 commit cca6f86
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions demo/WebAuthn.Net.Demo.Mvc/wwwroot/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ const Alerts = {
usernameInputEmpty: () => alert("Username input is empty"),
credentialsGetApiNull: () => alert("navigator.credentials.get returned null"),
credentialsCreateApiNull: () => alert("navigator.credentials.create returned null"),
getAuthenticatorDataInvalid: () => alert("Invalid data from getAuthenticatorData() method. Expected ArrayBuffer")
getAuthenticatorDataInvalid: () => alert("Invalid data from getAuthenticatorData() method. Expected ArrayBuffer"),
getPublicKeyInvalid: () => alert("Invalid data from getPublicKey() method. Expected ArrayBuffer")
};

// API
Expand Down Expand Up @@ -143,10 +144,13 @@ const API = {
if (newCredential.response.getPublicKey) {
const responsePublicKey = newCredential.response.getPublicKey();
const isValid = responsePublicKey instanceof ArrayBuffer;
if (isValid) {
if (responsePublicKey === null) {
publicKey = null;
} else if (isValid) {
publicKey = coerceToBase64Url(responsePublicKey);
} else {
publicKey = null;
Alerts.getPublicKeyInvalid();
return;
}
}

Expand Down

0 comments on commit cca6f86

Please sign in to comment.