(username: string)
| 192 | } |
| 193 | |
| 194 | export async function auth(username: string): Promise<boolean> { |
| 195 | const publicKey = (await getPublicKey( |
| 196 | username |
| 197 | )) as PublicKeyCredentialRequestOptions |
| 198 | console.log('auth get response:', publicKey) |
| 199 | publicKey.challenge = asArrayBuffer(publicKey.challenge as unknown as string) |
| 200 | if ( |
| 201 | publicKey.allowCredentials !== undefined && |
| 202 | publicKey.allowCredentials.length > 0 |
| 203 | ) { |
| 204 | publicKey.allowCredentials[0].id = asArrayBuffer( |
| 205 | publicKey.allowCredentials[0].id as unknown as string |
| 206 | ) |
| 207 | // TODO: if a user attempts to re-register they'll be given the option |
| 208 | // To scan a QR code to restore if any of the existing credentials don't |
| 209 | // Still exist. We may want to add the ability to register multiple passkeys. |
| 210 | // We might be able to use aaguid to determine machine uniqueness |
| 211 | } |
| 212 | let creds |
| 213 | try { |
| 214 | creds = await navigator.credentials.get({ publicKey }) |
| 215 | } catch (error) { |
| 216 | console.error('refused:', error) |
| 217 | return false |
| 218 | } |
| 219 | await post(username, creds as PublicKeyCredential) |
| 220 | return true |
| 221 | } |
nothing calls this directly
no test coverage detected