forked from clerk/javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebauthn.ts
30 lines (26 loc) · 827 Bytes
/
webauthn.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { isValidBrowser } from './browser';
function isWebAuthnSupported() {
return (
isValidBrowser() &&
// Check if `PublicKeyCredential` is a constructor
typeof window.PublicKeyCredential === 'function'
);
}
async function isWebAuthnAutofillSupported(): Promise<boolean> {
try {
return isWebAuthnSupported() && (await window.PublicKeyCredential.isConditionalMediationAvailable());
} catch (e) {
return false;
}
}
async function isWebAuthnPlatformAuthenticatorSupported(): Promise<boolean> {
try {
return (
typeof window !== 'undefined' &&
(await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable())
);
} catch (e) {
return false;
}
}
export { isWebAuthnPlatformAuthenticatorSupported, isWebAuthnAutofillSupported, isWebAuthnSupported };