Skip to content

Commit 7c116d2

Browse files
committed
Add a supported() function to test WebAuthn support.
1 parent dd160de commit 7c116d2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {
77
export {
88
create,
99
get,
10+
supported,
1011
} from "./webauthn";
1112
export {
1213
schema,

src/webauthn.ts

+14
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ export async function get(requestJSON: CredentialRequestOptionsJSON): Promise<Pu
1414
const response = (await navigator.credentials.get(request)) as PublicKeyCredential;
1515
return convert(bufferToBase64url, publicKeyCredentialWithAssertion, response);
1616
}
17+
18+
declare global {
19+
interface Window {
20+
PublicKeyCredential: any | undefined;
21+
}
22+
}
23+
24+
// This function does a simple check to test for the credential management API
25+
// functions we need, and an indication of public credential authentication
26+
// support.
27+
// https://developers.google.com/web/updates/2018/03/webauthn-credential-management
28+
export function supported(): boolean {
29+
return !!(navigator.credentials && navigator.credentials.create && navigator.credentials.get && window.PublicKeyCredential);
30+
}

0 commit comments

Comments
 (0)