@@ -24,6 +24,7 @@ type Result<T, E> =
24
24
| { ok : false , error : E , more ?: unknown }
25
25
26
26
type WebAuthnError =
27
+ | 'webauthn_unavailable'
27
28
| 'timeout'
28
29
| 'network_error'
29
30
| 'bad_request'
@@ -63,14 +64,10 @@ class SDK {
63
64
return ! ! window . PublicKeyCredential
64
65
}
65
66
66
- private requireWebAuthn ( ) {
67
- // if (!this.isWebAuthnAvailable) {
68
- // throw new Error
69
- // }
70
- }
71
-
72
67
async startAuth ( user : UserAuthenticationInfo ) : Promise < AuthResponse > {
73
- this . requireWebAuthn ( )
68
+ if ( ! this . isWebAuthnAvailable ) {
69
+ return { ok : false , error : 'webauthn_unavailable' }
70
+ }
74
71
const res = await this . api ( '/auth/createOptions' , { user } ) as Result < CredentialRequestOptionsJSON , WebAuthnError >
75
72
if ( ! res . ok ) {
76
73
return res
@@ -80,12 +77,14 @@ class SDK {
80
77
}
81
78
82
79
async startRegister ( user : UserRegistrationInfo ) : Promise < RegisterResponse > {
80
+ if ( ! this . isWebAuthnAvailable ) {
81
+ return { ok : false , error : 'webauthn_unavailable' }
82
+ }
83
83
// If you do this inside the try/catch it seems to fail. Some sort of race
84
84
// condition w/ the other request being canceled AFAICT. Doesn't make total
85
85
// sense to me and may be a browser specific issue.
86
86
const signal = this . cancelExistingRequests ( )
87
87
try {
88
- this . requireWebAuthn ( )
89
88
// If user info provided, send only the id or handle. Do NOT send name or
90
89
// displayName.
91
90
let remoteUserData : UserIdOrHandle | undefined
@@ -117,6 +116,9 @@ class SDK {
117
116
}
118
117
119
118
async handleAutofill ( callback : ( arg0 : AuthResponse ) => void ) {
119
+ if ( ! this . isWebAuthnAvailable ) {
120
+ return false
121
+ }
120
122
if ( ! PublicKeyCredential . isConditionalMediationAvailable ) {
121
123
return false
122
124
}
0 commit comments